首页 > 编程语言 > 详细

C/C++ 读文件

时间:2020-03-04 15:19:26      阅读:80      评论:0      收藏:0      [点我收藏+]

读文件

 

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);

  

 

C/C++ 读文件

原文:https://www.cnblogs.com/yangwenhuan/p/12409467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!