读取方式: 逐词读取, 词之间用空格区分,遇到"."就停止读取,返回的内容存取在vector
//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);
}
}
c++怎么学习?c++怎么入门?c++在哪学?c++怎么学才快?不用担心,这里为大家提供了c++速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号