Hi,
Is there a way to read the contents of a text file line by line? For example, I have a text file which has two numbers on two different lines like this:
4
5
...is there a way in C++ to load the text file, and then take the '4' from line one and assign it to a variable, and then read the '5' from line two and assign it to a separate variable? e.g:
Failing that, is there a way to define variables in a text file, for example if I have a text file with the following contents:Code:// Code to open text file and read the values of lines one and two. int line1, line2; line1 = textfile.line1; line2 = textfile.line2; cout << line1 << " is the first line of the file, and " << line2 << " is the second line." << endl;
variable1 = 4
variable2 = 5
...is it possible to define variable1 and variable2 in a program, open the text file and then assign the values given to variable1 and variable2 in the text file to the variables in the program?
Thanks!