[help] reading a file

So, I'm trying to write a program which reads a file I wrote to input data into a program.

here's my file contents
1
2
3
4
text1
text2a text2b
text3
text4a text4b


What I want to do is have a whole line in one string. so I want to do something like :
1
2
3
4
5
6
7
8
ifstream file("file.name");
vector <string> temp;
temp.clear();
temp.resize(4, "-1");
for(int i = 0; i < 4; i++)
{
   file >> temp[i];
}


however, after inputting text2a, it ends the loop, and puts text2b into temp[2] instead of temp[1], thus overloading the vector, and causing some pretty big problems.

My question : How would I go about putting 2 or more variables in one line from the file, into a single string, while the file itself has a variable of entities per given line?
Are you looking for getline(file, temp[i]); ?
Looks like that's what I needed. Thanks!
Topic archived. No new replies allowed.