2 Replies - 698 Views - Last Post: 11 November 2010 - 10:24 PM Rate Topic: -----

#1 Guest_noname*


Reputation:

write the contents of the list into a file

Posted 11 November 2010 - 10:17 PM

This does not compile

#include <iostream>
#include <list>
using namespace std;

int main(){
    
    list<char *> ag ;
    
    ag.push_front("aA BB");
    ag.push_front(" HGT ");
  
  ofstream myfile;
  myfile.open ("example.txt");
  list<char *>::iterator it;

  for ( it=ag.begin() ; it != ag.end(); it++ ){
    myfile << *it;        
      
}
  myfile.close();
 return 0;
    
}



I want to write the contents of the list into a file

error :-


In the function int main
aggregate std::ofstream myfile has incomplete type and cannot be defined




Is This A Good Question/Topic? 0

Replies To: write the contents of the list into a file

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4133
  • View blog
  • Posts: 12,858
  • Joined: 25-December 09

Re: write the contents of the list into a file

Posted 11 November 2010 - 10:23 PM

You have not included the include file for ofstream. It is in "fstream"

Jim
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: write the contents of the list into a file

Posted 11 November 2010 - 10:24 PM

** Renamed title to be more descriptive **
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1