C++从文件中按照单词读取内容
2018-07-20 来源:open-open
读取方式: 逐词读取, 词之间用空格区分,遇到"."就停止读取,返回的内容存取在vector<string>中
//read data from the file, Word By Word
//when used in this manner, we'll get space-delimited bits of text from the file
//but all of the whitespace that separated words (including newlines) was lost.
//http://www.sharejs.com
vector<string> ReadDataFromFileWBW()
{
ifstream fin("Input.txt");
string strWord("");
vector<string> v;
while( fin >> strWord )
{
//字符串string类的比较要用compare函数
if (strWord.compare(strWord.length()-1, 1, ".") == 0)
{
strWord.erase(strWord.length()-1, 1);
v.push_back(strWord);
return v;
}
v.push_back(strWord);
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐