Problem with I/O

Hello!I new to cpp and i have a problem with my code.
Well i have an array with objects...
1
2
  Cell *catalog;
  catalog=new Cell[SIZE];


and i want to put each cell in an output file so my thought...
1
2
3
4
5
6
  ofstream outfile;
  outfile.open("catalog.txt");
  for(int i=0;i<100;i++){
       outfile<<catalog[i].printCell();	
  }
  outfile.close();


were the method printCell() is void and print each cell of catalog
My compile crashes crashes [Error] no match for 'operator<<' in 'outfile << (catalog + ((sizetype)(((long long unsigned int)i) * 16ull)))->Cell::printCell()'

Please help guys...:D
Last edited on
Why you using a pointer and new for something like that? Makes the code more error prone. Also what is your printCell returning? Otherwise you may want to overload the operator << and just output each cell that way.

I m using a pointer and a new because i have to initialize an array with a big
size(200000).The printCell is a void method it just print the cell
This is in cell class...
1
2
3
void printCell(){
      cout<<id_counter<<"-"<<id_number;
}


when i m using in main the printCell() without insert the outfile it works...
1
2
3
for(int i=0;i<100;i++){
       catalog[i].printCell();	
}

Prints for each loop two numbers

So why i can't put the two numbers in the outfile?
So in otherwords you are trying to add nothing to the output stream. What I would do is give the printcell function a parameter of the ofstream (by reference) then replace cout with out or what ever name in your parameter:


1
2
3
4
5
6
7
8
9
void Cell::printCell( ofstream &out )
{
    out << id_counter << '-' << id number;
}

//in your main

for( int i = 0; i < 100; ++i )
    catalog[i].printCell();
Thats it!!!thanks a lot:-)
Topic archived. No new replies allowed.