Jump to content
SubSpace Forum Network

Recommended Posts

Posted

im to lazy to go to mgb forum's so ill post here

1) How do you delete a file using ofstream();?

2) Can you output Strings with ofstream();?

 

1: I need to delete a file.

2: When i use a string in the output of ofstream() it gives strange codes.

String p_bounty = "Witchie NL";

ofstream file("textfile.txt", ios::app);
if (file)
{
file << "blabla:" << p_bounty	<< endl;
}

It writes this: blabla:00C41F50

Posted

You can't delete a file using ofstream. You need to use a system call. You can, however, clear a file's contents:

 

// clear textfile.txt's contents
ofstream fout("textfile.txt");
if (fout.fail())
{
// error
}
else
fout.close();

 

As for outputting a String to a file, Drake was correct:

 

String p_bounty = "Witchie NL";

ofstream file("textfile.txt", ios::app);

if (!file.fail())
{
file << "blabla:" << p_bounty.msg	<< endl;
file.close();
}

Posted

ok thx that was what i needed

 

Edit: Added: And its working fine. I was adding some more stuff to my plugin and you dont wana know what happened. (if i tryed to start mervbot it came up with and error window and crashed the bot duno why it was coused but i removed all extra code and it worked fine again :S)

Guest
This topic is now closed to further replies.
×
×
  • Create New...