Read file for code JAM compitation

How to read the file , to take input in single line code
Example :
file name : 1.txt
content :
20
10
11

I want to read 20 , 10 , 11 line by line
Use fstream:

http://www.cplusplus.com/reference/fstream/fstream/?kw=fstream

Especially operator>>

1
2
3
fstream fs; // You need to open the file
...
  fs >> value1 >> value2 >> value3;



If there are whitspaces involved you might use getline(...):

http://www.cplusplus.com/reference/string/string/getline/?kw=getline
Hi coder777,
But the requirement is I don't know the number of values , It may be n Number of input not three.
Then you need a loop:
1
2
3
4
while(fs >> value) // Reads the data as long as it can (until end of file)
{
  // put value into a containe like array or list
}
Topic archived. No new replies allowed.