LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-27-2006, 06:36 AM   #1
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
Appending to a log file (C++)


hey there.

I'm appending to a log file many messages and I decided to use system (to call for the shell via C++) so I'm doing this :

system(echo "found error in input inserted by user at" >> logfile && date >> logfile);

but my question is how can I append variable to the text such as :

void myFunc(char[] myCommentToLog)
{
system (myCommentToLog >> logfile);
}

it doesn't work... have you got any idea to offer how to solve it? or how to add the variable (myCommentToLog) in other way?


Thanks!
 
Old 10-27-2006, 09:03 AM   #2
nhydra
Member
 
Registered: May 2006
Distribution: Fedora Core, FreeSpire, PC-BSD, NetBSD
Posts: 96

Rep: Reputation: 15
You can do it in that way:
int some_int_var;

fprintf (file_handler, "Some text %i", some_int_var);

Last edited by nhydra; 10-27-2006 at 09:05 AM.
 
Old 10-27-2006, 09:14 AM   #3
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
Just make sure that you open the file for appending.
 
Old 10-27-2006, 09:20 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You can do something like:

Code:
ofstream out("myfile", ios::app);
out << myCommentToLog;
Edit: obviously you'll need to include fstream. Also, remember to close the file afterwards (with out.close()). One last thing: you know C++ has a string class, right?
 
Old 10-27-2006, 09:57 AM   #5
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Nylex
You can do something like:

Code:
ofstream out("myfile", ios::app);
out << myCommentToLog;
Edit: obviously you'll need to include fstream. Also, remember to close the file afterwards (with out.close()). One last thing: you know C++ has a string class, right?
thanks.. and yes, I do know that.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
appending a file circuit_girl Programming 8 10-01-2006 11:00 AM
Sed(?); Appending a comma-delineated file ice_hockey Linux - General 2 05-27-2005 08:42 AM
Appending a string to a file JStew Linux - General 13 03-04-2003 03:48 PM
Appending current date and time to a file frankietomatoes Linux - General 5 11-18-2002 02:09 PM
sending a mail appending a file saavik Linux - Newbie 4 07-12-2002 03:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration