A
A.Leopold
hello,
is there a c++ equivalent function to the c-function 'sprintf'?
Thank you,
leo
is there a c++ equivalent function to the c-function 'sprintf'?
Thank you,
leo
hello,
is there a c++ equivalent function to the c-function 'sprintf'?
juanvicfer said:Maybe you want to use stringstream.
hello,
is there a c++ equivalent function to the c-function 'sprintf'?
You can also check out boost::format, which can be
easier to work with than stringstream:
http://www.boost.org/doc/libs/1_36_0/libs/format/doc/format.html
Sean
A.Leopold said:
ok, I asked, cause my compiler (VS05) is complaining about the use of
sprintf ....
thank you, that looks much more convenient!
Pascal said:I guess it's rather ::sprintf (with extern "C" { / #include <stdio.h>
/ }).
Default User said:What would make you guess something like that?
Pascal said:First, AFAIK, C functions are in the "root" namespace; to avoid
refering a different object in the current namespace, it's advised (in
various style guides) to qualify C functions.
Then, using a function without declaring it would make a sane compiler
complain, so it's good practice to include some header declaring it
before using it.
Pascal said:First, AFAIK, C functions are in the "root" namespace;
to avoid
refering a different object in the current namespace, it's advised (in
various style guides) to qualify C functions.
Then, using a function without declaring it would make a sane compiler
complain, so it's good practice to include some header declaring it
before using it.
ok, I asked, cause my compiler (VS05) is complaining about the use of
sprintf ....
Jeff said:Assuming that line is preceded by "using std::sprintf;".
is there a c++ equivalent function to the c-function 'sprintf'?
Yannick Tremblay said:sprintf is a buffer overflow waiting to happen.
Use snprintf instead.
Where are you seeing this?
IME, it's vanishingly rare, and generally a sign of
incompetence.
He didn't say it was used where necessary, he said people
preferred it.
And where on earth are you still having trouble with <c*>?
They've worked well for me for at least the last years or so
(using mostly GCC).
Which leads to porting issues when one compiler does and another does not.Yes. People prefer it because they know what they are getting.
The fact that most implementations didn't implement what the
standard required in the <c...> headers meant that using them
meant that you didn't know what you were getting.
We also tend to consider Posix headers as "standard" and dislike havingFor those of us who work under Posix, or have to support Posix,
there's an additional issue---Posix modifies the definition of
some of the standard C headers. And who knows whether the
<c...> headers will respect the Posix standard; there isn't a
Posix standard for the <c...> headers.
That is true. It is also irrelevant: they're not going to go away,
despite the wishes of some people early in the standardization effort.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.