I have a question about file input in c++. I want to be able to create a string variable and read in a SENTENCE from the file. How would I do this? This is the code I have so far.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string word;
ifstream fin;
// Open the file
fin.open("file.txt");
// Read in the sentence from the file
fin >> word;
cout << word << endl;
return 0;
}
The problem is, when I try to read in a sentence from the file, it only reads in a word and not the sentence.
So if I had a sentence in a textfile (assuming that there is no line break) it would only print out the single word.
How would I fix this?