
-----------------------------------
JR
Thu Jan 06, 2005 4:44 pm

fstream problem
-----------------------------------
ok so i have this function thats suppose to write into a file, now i get an error and it doesnt work somewhy


void write ()
{
fstream fin;
fin.open("files/titles.txt",ios::out|ios::app);
char* data;
coutdata;

fin.write(data,int);

fin.close();

}


-----------------------------------
wtd
Thu Jan 06, 2005 5:53 pm


-----------------------------------

No space between the functiona name and parentheses.

void write() 
{ 

}
Don't use "fstream".  You're outputting to this stream, so use the ofstream class instead.  Also, this is an output file, but you use something that's commonly seen as "file in".  Bad programmer!

ofstream output_file;
Why separately call openimmediately after the declaration?  Just let the constructor do the work for you.

ofstream output_file("files/titles.txt",ios::out|ios::app);
You're using a char array?  That's C madness.  This is C++ and we have proper strings.

std::string data;
You're using cout without a namespace qualifier and \n instead of std::endl.  Madness.

std::cout  data;
Since we're now using strings that know their own length we don't have to use some crazy write function.

output_file 