我有一个包含不同数量的单词/行的文本文件。一个例子是:
Hi
My name is Joe
How are you doing?
我想抓住用户输入的任何内容。所以如果我搜索乔,它会得到那个。不幸的是,我只能输出每一行而不是单词。我有一个向量逐行保存这些中的每一个
vector<string> line;
string search_word;
int linenumber=1;
while (cin >> search_word)
{
for (int x=0; x < line.size(); x++)
{
if (line[x] == "\n")
linenumber++;
for (int s=0; s < line[x].size(); s++)
{
cout << line[x]; //This is outputting the letter instead of what I want which is the word. Once I have that I can do a comparison operator between search_word and this
}
}
所以现在line[1] = Hi
,line[2] = My name is Joe
.
我怎样才能得到它,我可以得到实际的话?