473,569 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sprintf equivalent in c++

hello,

is there a c++ equivalent function to the c-function 'sprintf'?

Thank you,

leo

Oct 9 '08 #1
44 7795
On 2008-10-09 09:33:41 -0400, "A.Leopold" <an************ *@himt.desaid:
>
is there a c++ equivalent function to the c-function 'sprintf'?
Yes. Its name is sprintf.

--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)

Oct 9 '08 #2
;)
ok, I asked, cause my compiler (VS05) is complaining about the use of
sprintf ....

Pete Becker schrieb:
On 2008-10-09 09:33:41 -0400, "A.Leopold" <an************ *@himt.desaid:
>>
is there a c++ equivalent function to the c-function 'sprintf'?

Yes. Its name is sprintf.
Oct 9 '08 #3
On Oct 9, 3:33*pm, "A.Leopold" <andreas.leop.. .@himt.dewrote:
hello,

is there a c++ equivalent function to the c-function 'sprintf'?
Maybe you want to use stringstream.
>
Thank you,

leo
Oct 9 '08 #4


juanvicfer schrieb:
On Oct 9, 3:33 pm, "A.Leopold" <andreas.leop.. .@himt.dewrote:
>hello,

is there a c++ equivalent function to the c-function 'sprintf'?

Maybe you want to use stringstream.
ok, I will have a look at stringstream

Oct 9 '08 #5
On Oct 9, 9:33 am, "A.Leopold" <andreas.leop.. .@himt.dewrote:
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...oc/format.html

Sean

Oct 9 '08 #6


se************* @yahoo.com schrieb:
On Oct 9, 9:33 am, "A.Leopold" <andreas.leop.. .@himt.dewrote:
>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...oc/format.html

Sean
thank you, that looks much more convenient!
Oct 9 '08 #7
"A.Leopold" <an************ *@himt.dewrites :
;)
ok, I asked, cause my compiler (VS05) is complaining about the use of
sprintf ....
I guess it's rather ::sprintf (with extern "C" { / #include <stdio.h/ }).

But if you want some safety, you'd use ::snprintf, and if you don't want to implement
the safety yourself, you could rather use lisp^W std::ostringstr eam.

std::ostringstr eam s; s<<"Hi "<<world<<std:: endl;
std::string str =s.str();
const char* cstr=s.c_str();

--
__Pascal Bourguignon__
Oct 9 '08 #8
On Thu, 09 Oct 2008 17:12:56 +0200, A.Leopold wrote:
se************* @yahoo.com schrieb:
>On Oct 9, 9:33 am, "A.Leopold" <andreas.leop.. .@himt.dewrote:
>>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...oc/format.html

Sean

thank you, that looks much more convenient!
There is also boost::lexical_ cast (something like a "cheap and cheerful"
version of stringstream formatting):

http://www.boost.org/doc/libs/1_36_0...xical_cast.htm

--
Lionel B
Oct 9 '08 #9
Pascal J. Bourguignon wrote:
"A.Leopold" <an************ *@himt.dewrites :
;)
ok, I asked, cause my compiler (VS05) is complaining about the use
of sprintf ....

I guess it's rather ::sprintf (with extern "C" { / #include <stdio.h>
/ }).
What would make you guess something like that?


Brian
Oct 9 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
118504
by: Frank Neuhaus | last post by:
Hey Iam occaisonally using something like char buffer; sprinf(buffer,"Hello test %d %s",someint,somestring); Is there any _convenient_ and buffer overflow secure equivalent for that using std::string? Thanks
10
9925
by: ios | last post by:
Hi Can someone tell me what is different between below case? strcpy(eventname, "MDCX_RSP"); and sprintf(eventname, "MDCX_RSP"); Thanks, Leon
4
4403
by: William Stacey [MVP] | last post by:
If val is a long, what is the String format conversion of this in c#? TIA! sprintf(retbuf,"%d.%.2d", val/100, val%100); -- William Stacey
4
2749
by: adamrobillard | last post by:
Hi, I went through most of the FAQ but did not find any direct references formatting outputed data. If I have a application in C like so: void main(void) { int nValue = 100; double dPi = 3.14159265; char sName = {"Morpheus"};
10
4180
by: Saurabh | last post by:
Hi all, I am working on RedHat Linux GCC 3.0. I am trying to convert a long to string through sprintf. but i m getting segmantation fault. I tried snprintf also but no avail.here is the piece of code.. ---------------------------- long myLong=200000; char myStr;
66
3071
by: gyan | last post by:
Hi All, I am using sprintf and getting starnge output in following case char temp_rn; memset(temp_rn,'\0',12); sprintf(temp_rn,"0%s",temp_rn); the final value in temp_rn is 00 how it is behaving like this, when source string and output string is
2
2725
by: jasonwthompson | last post by:
I'm converting some old C code to C++. Although I'm not concerned about converting every C item to C++ I'm in a situation in which using an ostringstream makes more sense than using sprintf. Here's my problem: In sprintf, one could use the %g symbol to indicate that I either wanted scientific notation or a simple floating point, whichever...
173
13824
by: Ron Ford | last post by:
I'm looking for a freeware c99 compiler for windows. I had intended to use MS's Visual C++ Express and use its C capability. In the past with my MS products, I've simply needed to make .c the filetype to invoke the C compiler. Here's a link http://www.microsoft.com/express/download/#webInstall The download is 2.6 megs, which is near a...
0
7711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7938
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8145
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6317
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3679
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2128
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.