0

i have the following code...according to my book both the files should open...but it opens both the files...writes into them....but when i open them for reading....only one opens up....pls see where i am wrong....

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    ofstream fout;
    fout.open("country.txt");
    fout<<"United States of America\n";
    fout<<"United Kingdom\n";
    fout<<"South Korea\n";
    
    fout.close();
    
    fout.open("capital.txt");
    fout<<"Washington\n";
    fout<<"London\n";
    fout<<"Seoul\n";
    
    fout.close();
    
    const int n= 80;
    char line[n];
    
    ifstream fin;
    
     
   
    cout<<"\nContents of capital file\n";
    fin.open("capital.txt",ios::in);
   
   
              fin.getline(line, n);
              cout<<line;
       }while(fin);
     fin.close();
     fin.open("country.txt");
      cout<<"\nContents of country file";
        do
    {
   
              fin.getline(line, n);
              cout<<line;
 }while(fin);
    fin.close();
   
    
  
     system("pause");
}
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jasleen12345
0

sorry i missed a do{ in line 30........but still i am having same problem......

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.