C/C++ 读文件
作者:互联网
读文件
std::ifstream infile; infile.open("/Users/yangwenhuan/IVP_workbench/test/graph.prototxt"); std::stringstream buf; buf << infile.rdbuf(); string prototxt_str = buf.str(); infile.close();
FILE *pfile = fopen("/Users/yangwenhuan/IVP_workbench/test/graph.prototxt", "r"); char *data; if (pfile == NULL) { cout << "Read prototxt fail!" << endl; return -1; } fseek(pfile, 0, SEEK_END); int length = ftell(pfile); data = (char *)malloc((length + 1) * sizeof(char)); rewind(pfile); length = fread(data, 1, length, pfile); data[length] = '\0'; fclose(pfile); string prototxt_str(data);
std::ifstream infile("/Users/yangwenhuan/IVP_workbench/test/graph.prototxt"); std::istreambuf_iterator<char> begin(infile); std::istreambuf_iterator<char> end; std::string prototxt_str(begin, end);
标签:std,文件,workbench,Users,yangwenhuan,C++,prototxt,infile 来源: https://www.cnblogs.com/yangwenhuan/p/12409467.html