讀取方式: 逐詞讀取, 詞之間用空格區分,遇到"."就停止讀取,返回的內容訪問在vector中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | vector<string> ReadDataFromFileWBW()
{
ifstream fin( "Input.txt" );
string strWord( "" );
vector<string> v;
while ( fin >> strWord )
{
if (strWord.compare(strWord.length()-1, 1, "." ) == 0)
{
strWord.erase(strWord.length()-1, 1);
v.push_back(strWord);
return v;
}
v.push_back(strWord);
}
}
|
登入後複製