need assisantence on this problem

Write a program named FileIO.cpp. In your program, open the input file in.txt, check to see if it opens successfully, and then read the names from the input file and print to screen the names of all the Presidents’ numbered, so number 1 before displaying the first name, print the number 2 before displaying the second name, and so on for each name in the file. This process continues until all the names from the input file are read.

Your output on to the screen should look like:

1. George Washington

2. John Adams

3. Thomas Jefferson

4. James Madison

5. James Monroe

6. John Quincy Adams

I don't know how to add a number in front of the presidents name
heres what I have so far:

#include <fstream>
using namespace std;
int main () {
int i;
ofstream fout;
ifstream gout;
fout.open ("presidents.txt");
fout<< "George Washington"<<endl;
fout<< "John Adams"<<endl;
fout<< "Thomas Jefferson"<<endl;
fout<< "James Monroe"<<endl;
fout<< "John Quincy Adams"<<endl;
fout.close();

gout.open("presidents.txt");
if(gout.fail())
{
cout<<"file open fail!";
}

else {
string president_name;
while (getline(gout,president_name))
cout<<president_name <<endl;
}
gout.close ();

}
multi-posts don't increase your chances of getting help, often its counterproductive:
http://www.cplusplus.com/forum/general/212933/
Topic archived. No new replies allowed.