for example you have a:
string test;

void ExampleWindow::on_clicked(){
                ofstream myfile;
                string test;
  		myfile.open ("/home/ws14/Desktop/trunk/minisip/minisip/share/test.txt");
     		mydialfile << test;
   		mydialfile.close();
}

how can I just add or insert a value on the file(test.txt). not just overwrite the file(test.txt) when the function(on_clicked) is being called.
All I need is if the function(on_clicked) is being called. The value of test is must add/insert(not ovewrite it) on the file(test.txt).
please help me.... thank you!

Recommended Answers

All 5 Replies

myfile.open(filename,ios::app);

The easiest way would be to use the ios::app flag, this will open the file in append mode if the file exists, if it can't find the file, a new one will be created.

ofstream myfile;
myfile.open("path\filename.ext", ios::app );

Cheers for now,
Jas.

ofstream filestr;

filestr.open("path\test.ext", ios::app );

commented: It took you an hour longer to come up with the same solution as above. Only without code-tags... -3

thanks for the help! I already know. But thanks to all hope to help me again.

This is my next question: how to get a document from root?
because I have this code:

myfile.open ("/home/ws14/Desktop/test.txt");

But I need to change the path home/ws14 if I change user. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.