943,703 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 548
  • C++ RSS
Apr 23rd, 2009
0

please help me on this...:(

Expand Post »
for example you have a:
string test;
C++ Syntax (Toggle Plain Text)
  1.  
  2. void ExampleWindow::on_clicked(){
  3. ofstream myfile;
  4. string test;
  5. myfile.open ("/home/ws14/Desktop/trunk/minisip/minisip/share/test.txt");
  6. mydialfile << test;
  7. mydialfile.close();
  8. }

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!
Reputation Points: 46
Solved Threads: 7
Junior Poster in Training
valtikz is offline Offline
51 posts
since Apr 2009
Apr 23rd, 2009
0

Re: please help me on this...:(

C++ Syntax (Toggle Plain Text)
  1. myfile.open(filename,ios::app);
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Apr 23rd, 2009
0

Re: please help me on this...:(

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.

C++ Syntax (Toggle Plain Text)
  1. ofstream myfile;
  2. myfile.open("path\filename.ext", ios::app );

Cheers for now,
Jas.
Reputation Points: 590
Solved Threads: 123
Practically a Master Poster
JasonHippy is offline Offline
672 posts
since Jan 2009
Apr 23rd, 2009
-1

Re: please help me on this...:(

ofstream filestr;

filestr.open("path\test.ext", ios::app );
Reputation Points: 1
Solved Threads: 2
Light Poster
shefeekj is offline Offline
37 posts
since Apr 2009
Apr 23rd, 2009
0

Re: please help me on this...:(

thanks for the help! I already know. But thanks to all hope to help me again.
Reputation Points: 46
Solved Threads: 7
Junior Poster in Training
valtikz is offline Offline
51 posts
since Apr 2009
Apr 23rd, 2009
0

Re: please help me on this...:(

This is my next question: how to get a document from root?
because I have this code:
C++ Syntax (Toggle Plain Text)
  1. myfile.open ("/home/ws14/Desktop/test.txt");

But I need to change the path home/ws14 if I change user. Thanks!
Reputation Points: 46
Solved Threads: 7
Junior Poster in Training
valtikz is offline Offline
51 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: how to convert c to c++
Next Thread in C++ Forum Timeline: Visual C++ help?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC