Where is va_args now?
In my program I often need to use parameters to create log messages and to create string commands. For example:
This is not real code, but illustrate what I mean. I had to create an exception class that allows me to create error messages with parameters in a straightforward manner, using va_args. This is the constructor:
printf("Time of event %s:\nEvent: %s\n", event_time, description);
The code is not perfect, I know. I do not know how to do it better. However, the point is: is this kind of construction possible in C++? I was changing char* to string, now I can't use sprintf to format my command in one line. :(
Excecao::Excecao(const char* fmt, ...)
void Excecao::setStr(const char* fmt, va_list args)
vsnprintf(buffer, 1024, fmt, args);
_description = buffer;
Thanks any suggestion or comment.
In C++-style, you'd probably use stringstreams for that sort of thing. Check out the FAQ.
It is possible to use <cstdargs>, sprintf(), and any C function in C++, it's just not recommended.
I don't know cstdargs, I will take a look, thanks!
It's C's <stdarg.h> in C++. And I meant <cstdarg>. You know it, you're using it. :)
 Check out http://faq.cprogramming.com/cgi-bin/...&id=1043284385 [/edit]
If all the arguments are strings, you don't need sprintf or stringstreams. Just add the strings together with + or +=.