[C++] C++逐行读取.txt中的字符串 →→→→→进入此内容的聊天室

来自 , 2019-05-28, 写在 C++, 查看 127 次.
URL http://www.code666.cn/view/4afd521d
  1. #include <fstream>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.         ifstream in("1.txt");
  9.         ofstream out("2.txt");
  10.         string filename;
  11.         string line;
  12.  
  13.         if(in) // 有该文件
  14.         {
  15.                 while (getline (in, line)) // line中不包括每行的换行符
  16.                 {
  17.                         cout << line << endl;
  18.                         out << line << endl; // 输入到2.txt中
  19.                 }
  20.         }
  21.         else // 没有该文件
  22.         {
  23.                 cout <<"no such file" << endl;
  24.         }
  25.  
  26.         return 0;
  27. }

回复 "C++逐行读取.txt中的字符串"

这儿你可以回复上面这条便签

captcha