|
To work with file, take a look at ofstream. You can do things like that:
ofstream File("MyFile.txt");
int Variable = 10;
File<<"Text"<<Variable<<endl;
|
|
|
|
|
how to handle variable number of arguments in function?
TRACE( ... )
{
//check how many argc
//out put them to file
file<<"arg1 type";
file<
|
|
|
|
|
And how do you manage that with the TRACE macro ? It should be the same.
-- modified at 7:28 Tuesday 2nd May, 2006
To take your example:
TRACE(" %d %d\n", a,b)
Would be:
File<<a<<b<<endl;
|
|
|
|
|
I'm not going to manage it with TRACE macro, I mentioned that I need to write similar function like TRACE for outputing formatted string to file
9ine
|
|
|
|
|
9ine wrote: I mentioned that I need to write similar function like TRACE
This part was not clear. Now I see what you want to do. I never worked with functions with variable arguments list but you can take a look at the MSDN[^].
|
|
|
|
|
9ine wrote: how to handle variable number of arguments in function?
See va_arg() , va_start() , va_list , and va_end() .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
HI,
Your question doesn't explain itself fully.Please post some sort of relevant information on what type of application are you working on and some code if possible.
As far as I understand your question you want to write a formatted string to a file so You can use fprintf()
Vision is Always important and so is your ATTITUDE.
Wishes.
Anshuman Dandekar
-- modified at 7:31 Tuesday 2nd May, 2006
|
|
|
|
|
No I'd like to paste some "TRACE" like function in the release code which is run faster than in debug mode using TRACE().
When the code is executed we can output TRACE() messages to VC window but in release mode I'd like to substitute TRACE() function with something similar but puting its output to file
some hard C console app code:
....
....
TRACE(" %d %d", var1,var2);
...
...
change the same of TRACE() function to put (" %d %d", var1,var2) formated string to file by invoking just that function
9ine
|
|
|
|
|
Take a look at vfprintf .
Nibu thomas
Software Developer
|
|
|
|
|
Make couples of defines, and define TRACE to a function of yours in release mode.
In that function, do the formatting and file writing.
Then you can use the same TRACE-statements in debug as well as in relese mode, and the release-version vill write to a file of your choice.
I won't give you a code sample, since I'm likely to get flamed for it. But it can be done, quite easily.
Put your email address in your profile and I can email you a working example.
|
|
|
|
|
9ine@mail.ru
that would be great
9ine
|
|
|
|
|
You've got it.
I hope you will find it useful.
Kakan
|
|
|
|
|
Still have not recieved it.
I'm going to use just one file for log trace.
9ine
|
|
|
|
|
great thing, thanks, strange that you get 550 smtp error?
9ine
|
|
|
|
|
Actually this part of your idea is good - I am not so sure about the implementation though.
I would take a look at TRACE's implementation. It takes a while to wade through but you can learn a bit along the way. It eventually boils down to calling _snprintf (or _sntprintf for TCHAR usage) into a text buffer (1024 bytes long) and then calling OutputDebugString in AtlDebugAPI.cpp around line 306. OutputDebugString works in release and debug mode as long as a debugger is running.
What I am getting at is in release builds TRACE is compiled to no-ops so you can implement your own trace statements that do essentially the same thing. If you do it right you can disable them all by commenting out a few lines and recompiling.
Good luck.
|
|
|
|
|
There is always room for improvements.
The way I see it there is a distinction between "good" and "good enough"
In this case, the the objective was to get a way of tracing the app in a release build.
Of course, a guy can spend, say 10 hours, to get the trace code perfect in every aspect.
Or, spending 1 hour to get a code that's good enough, and the remaining 9 hours to do the actual debug.
IMO, the second alternative is the best, since it faster will lead to making the "debugee" work.
Correct me if I'm wrong, but that was the goal, wasn't it?
|
|
|
|
|
9ine wrote: I need to test system in release mode using similar to TRACE(" %d %d\n", a,b) geting variable number of arguments to formated string but saveing it to some file. Is there some code available
as others said, write to a file using sprintf or other stream writing. I use sprintf with a stream to sockets so that the debugger can be off system for embedded debugging as well as local.
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
|
|
|
|
|
Hi,
I have a new requirement to display the meesages in the DOS window instead of writing to a log file where the exe exists.Currently we can invoke an exe from commmand prompt which accepts a command line parameter.
Can someone please tell me how to display the message sin command prompt instead of writing to a log file .
Thanks,
|
|
|
|
|
It depends. cout << "Hello"; is one way but it depends. What type of .EXE is it (console or not)? What libraries are used?
Steve
|
|
|
|
|
HI,
I am using console exe.That exe is used for batch processing.
For example,
I run the command like
c:\>.....\abc.exe ordupd
here ordupd is the commandline paramter tat exe accepts
but i coudn't see any messages here eventhought i used getch() and cout statements
The process terminates to
c:\>... after completing the process.\
Thanks,
|
|
|
|
|
Make sure you #include <iostream> . Then you can write out text like this:
std::cout << "Hello";
If the std prefix annoys you there are a number of way to get rid out it. The quick and dirty method if to add a using namespace std to the .CPP file. NOTE: Adding a using directive to a header file will also work but its bad form.
Steve
|
|
|
|
|
Hi,
It's not working . I think its an MFC exe (inside initinstance () if i put cout<< statement , nothing is reflected in dos winndow.Please if you have any suggestions tell me.
Thanks,
|
|
|
|
|
You just want to know how to display the message in the console right (not how to get the command line arguments) ?
Just use cout for that:
int SomeVar = 5;
cout<<"Some Text"<<SomeVar;
|
|
|
|
|
I would write an interface layer (or class) that accepts your message and has a member variable that specifies the destination for the message.
In the old RTL functions, this would mean using fprintf to output the message but you specify the destination with a file structure pointer. Use stdout for the console or open up a file and pass that pointer to send it to a file.
This could be a global object that gets the destination via a call during your app's initialization. The idea is that you specify only one time where your messages go - not in every single instance.
I don't know what corresponding streams methods would be because I never use them.
|
|
|
|
|
hi
I want to look at the source code of CWnd,CButton,CListBox,CException,...... where to find these sources ?
thank you all
i have VS.net 2003
-- modified at 6:52 Tuesday 2nd May, 2006
|
|
|
|