![](/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.