fstream read a line at a time

closed account (EwCjE3v7)
How would I convert the following function to read a line into each element in the vector instead of a word at a time

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
vector<string> getfile()
{
	std::ifstream  file ("input.txt", std::ifstream::in);
	vector<string> line;
	
	while (file.good()) {
		string tmp;
		file >> tmp;
		line.push_back(tmp);
	}

	for (string s : line) {
		cout << s << endl;
	}

	file.close();
	return line;
}
Replace file >> tmp; with std::getline(file, tmp);
1
2
3
std::string tmp;
while (std::getline(file, tmp))
    line.push_back(tmp);
closed account (EwCjE3v7)
Thank you guys, posted at the same time :). Thank you once again.
Topic archived. No new replies allowed.