I have a text file with a varied number of words/lines. An example would be:
Hi
My name is Joe
How are you doing?
I'm wanting to grab whatever the user inputs. So if I search for Joe, it'll get that. Unfortunately, I am only able to output each line instead of the word. I have a vector that is holding each one of these line by line
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
}
}
So right now line[1] = Hi
, line[2] = My name is Joe
.
How would I get it to where I can get the actual word?