reading from a text file

I am writing a program in which i will be using 2 functions, one for writing integers into a text file & second for reading them back in integer form. while i did not faced in writing int say 100 numbers into a text file. i am stuck on reading from it. my program requirement is that, i want to read only one integer at a time when i call read function & when i call read function next time, it should return next number from the file. i think their can be 2 ways to solve this problem. first is that once i have read a number from the file, that number should be deleted & when i call read function next time, it will return next number from the file. in second method i can use pointer to keep track of them. i am not sure how to do it. please help.
To open a text file for output you can use this:

1
2
3
#include <fstream>

std::ofstream output("my_output_file.txt");


To write an int to the output file you can use this:

1
2
3
int i = 5;

output << i;



To open a text file for input you can use this:

 
std::ifstream input("my_input_file.txt");


To read an int from the input file you can use this:

1
2
3
int i;

input >> i;

Topic archived. No new replies allowed.