现在的位置: 首页 > 综合 > 正文

fstream一次把整个文本文件内容读到 string 里

2012年04月04日 ⁄ 综合 ⁄ 共 291字 ⁄ 字号 评论关闭

1, infile >> str 碰到回车空格就不继续了。

 

2,IOStream著名专家Dietmar Kuehl给过两个方法 

   std::ifstream in("some.file"); 
   std::istreambuf_iterator<char> beg(in), end; 
   std::string str(beg, end); 

或 

   std::ifstream in("some.file"); 
   std::ostringstream tmp; 
   tmp << in.rdbuf(); 
   std::string str = tmp.str();

抱歉!评论已关闭.