C++ 实现读取文本文件,按行读取

版权声明:学无止境,好好学习 https://blog.csdn.net/m0_38116269/article/details/88906896

直接放代码

#include <iostream>
#include <string>
#include "fstream"
using namespace std;

int main(){
    string label_file = "/home/wwh/Documents/caffe_files/resnet-18/labels.txt";
    std::ifstream labels(label_file.c_str());
    if(!labels.is_open()){
        cout<<"Can't open the label file!"<<endl;
        return -1;
    }
    string line;
    while(std::getline(labels, line)){
        cout<<line<<endl;
    }
    return 0;
}

先保存着,以后用时直接借鉴。

猜你喜欢

转载自blog.csdn.net/m0_38116269/article/details/88906896