I need to open a text file and assign numbers in the file to int variables.

I have a file in notepad that looks like this,

1
2
3
4


I want to make the program open the file and assign 1 2 3 and 4 to different integer variables.

1 will be value1
2 will be value2 , and so on.

I cannot get it to work, this is what I tried but when I tell it to display any of the values the numbers displayed are not correct or even close. Please help!

int value1;
int value2;
int value3;
int value4;
fstream file;
file.open ("numbers.txt");
file >> value1, value2, value3, value4;
cout << value1;
system ("pause");

file >> value1, value2, value3, value4;
replace the commas with >>
Last edited on
Topic archived. No new replies allowed.