[C++] 读出的文件遇到空格和换行都以换行的形式输出 →→→→→进入此内容的聊天室

来自 , 2019-08-25, 写在 C++, 查看 105 次.
URL http://www.code666.cn/view/5fa9e41b
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. void process(string s)
  8. {
  9.         cout<< s;
  10. }
  11. int main()//int argc,char* argv[]
  12. {
  13.         vector<string> files;
  14.         string fileName, s;
  15.  
  16.         cout<<"Enter filenames :(Ctrl+Z to end)"<<endl;
  17.         while (cin>>fileName)
  18.                 files.push_back(fileName);
  19.         ifstream input;
  20.         vector<string>::const_iterator it = files.begin();
  21.  
  22.         while (it != files.end())
  23.         {
  24.                 input.open(it->c_str());
  25.                 if (!input)
  26.                 {
  27.                         cerr<<"error :can not open file:" <<*it <<endl;
  28.                         input.clear();
  29.                         ++it;
  30.                 }
  31.                 else
  32.                 {
  33.                         while (input >> s)
  34.                                 cout<<s<<endl;
  35.                         input.close();
  36.                         input.clear();
  37.                         ++it;
  38.                 }
  39.         }
  40.         return 0;
  41. }
  42.  

回复 "读出的文件遇到空格和换行都以换行的形式输出"

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

captcha