[C++] C++从文件中按照单词读取内容 →→→→→进入此内容的聊天室

来自 , 2021-01-05, 写在 C++, 查看 122 次.
URL http://www.code666.cn/view/60cb558c
  1. //read data from the file, Word By Word
  2. //when used in this manner, we'll get space-delimited bits of text from the file
  3. //but all of the whitespace that separated words (including newlines) was lost.
  4. //http://www.sharejs.com
  5. vector<string> ReadDataFromFileWBW()
  6. {
  7.     ifstream fin("Input.txt");  
  8.     string strWord("");
  9.     vector<string> v;
  10.     while( fin >> strWord )
  11.     {
  12.     //字符串string类的比较要用compare函数
  13.         if (strWord.compare(strWord.length()-1, 1, ".") == 0)  
  14.         {
  15.             strWord.erase(strWord.length()-1, 1);
  16.             v.push_back(strWord);
  17.             return v;
  18.         }  
  19.         v.push_back(strWord);
  20.     }
  21. }
  22. //cpp/8896

回复 "C++从文件中按照单词读取内容"

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

captcha