ifstream in c++ ... more than one line in a single string

wxjunkie

Senior member
Nov 6, 2000
409
0
0
How can I assign more than one line from a simple text file or more than one word on a single line in a text file to one declared string?

Example... file.dat reads:
Anandtech Forums
29 September 2002


I want to assign "Anandtech Forums" from that file to a string named refName

ifstream inData;

string refName;

inData.open("file.dat")

inData >> refName;


How can I cause both words on the first line to be assigned to refName instead of just the first word, "Anandtech" ??
 

Damascus

Golden Member
Jul 15, 2001
1,434
0
0
fin.getline(string, number of chars to read);

That will read everything up to the first newline character. You can add a 3rd
parameter if you wanna go fishing for other characters.