I have a text file that has two words next to one another separated by a space. I am trying to read in the words using >>
but whenever I attempt to do this, it reads in the same word.
string word1;
string word2;
ifstream fin;
fin.open("text.txt");
while (!fout.eof())
{
fin >> word1;
cout << word1 << endl;
fin >> word2;
cout << word2 << endl;
}
The first word in the file is the. The second is happy. When I try to output the words, both are the. How should I go about reading in both words as separate variables?