![](/img/trans.png)
[英]C++: Reading from a txt file line by line and word by word with uneven amount of words each line
[英]getting a line from a file and then reading word by word. C++
我有一個特里,想要搜索txt文件的每一行中的常用字數。 我使用getline獲取該行但無法繼續。
我試過了
string s;
ifstream myfile;
myfile.open("user.txt");
getline(myfile,s);
string person(s);
istringstream iss(person);
do
{
string sub;
iss >> sub;
cout << sub << endl;
} while (iss);
但它說'std :: istringstream iss'有初始值但不完整的類型
#include <sstream> // std::istringstream
std::string s;
std::ofstream myfile("user.txt");
std::getline(myfile, s);
std::istringstream iss(s);
std::string sub;
while(iss >> sub)
{
cout << sub << endl;
}
你忘了#include <sstream>
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.