954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

please help me on this...:(

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!

valtikz
Junior Poster in Training
52 posts since Apr 2009
Reputation Points: 46
Solved Threads: 7
 
myfile.open(filename,ios::app);
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
 

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.

JasonHippy
Master Poster
772 posts since Jan 2009
Reputation Points: 590
Solved Threads: 125
 

ofstream filestr;

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

shefeekj
Light Poster
37 posts since Apr 2009
Reputation Points: 1
Solved Threads: 2
 

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

valtikz
Junior Poster in Training
52 posts since Apr 2009
Reputation Points: 46
Solved Threads: 7
 

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!

valtikz
Junior Poster in Training
52 posts since Apr 2009
Reputation Points: 46
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You