473,396 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to use printf()-like formatting via string/iostream?

Hello,

Is there a means to use printf()-like formatting (eg:
http://www.mkssoftware.com/docs/man1/printf.1.asp ) using class string
and/or iostream constructs so that I need not have to define
fixed-size character buffers (like it appears that I have to do in
printf()...or maybe there's an alternative)?

-Matt
--
Remove the "downwithspammers-" text to email me.
Jul 23 '05 #1
3 2431
"Matt" <ma**@downwithspammers-mengland.net> wrote...
Is there a means to use printf()-like formatting (eg:
http://www.mkssoftware.com/docs/man1/printf.1.asp ) using class string
and/or iostream constructs so that I need not have to define
fixed-size character buffers (like it appears that I have to do in
printf()...or maybe there's an alternative)?


I am not sure where the question comes from (have you a good book that
talks about formatted output?) but please look at "stream manipulators",
declared in <iomanip> header. All necessary manipulators are there to
make the string stream output function the same as printf-based.

V
Jul 23 '05 #2
Matt wrote:
Hello,

Is there a means to use printf()-like formatting (eg:
http://www.mkssoftware.com/docs/man1/printf.1.asp ) using class string
and/or iostream constructs so that I need not have to define
fixed-size character buffers (like it appears that I have to do in
printf()...or maybe there's an alternative)?

-Matt
--
Remove the "downwithspammers-" text to email me.


If you're looking for the "%x"-formatting-style functionality of printf,
check out the boost format library
http://www.boost.org/libs/format/index.html

--
Regards,
Matthias
Jul 23 '05 #3

"Matthias" <no****@digitalraid.com> wrote in message
news:cu*************@news.t-online.com...
Matt wrote:
Hello,

Is there a means to use printf()-like formatting (eg:
http://www.mkssoftware.com/docs/man1/printf.1.asp ) using class string
and/or iostream constructs so that I need not have to define
fixed-size character buffers (like it appears that I have to do in
printf()...or maybe there's an alternative)?

-Matt
--
Remove the "downwithspammers-" text to email me.


If you're looking for the "%x"-formatting-style functionality of printf,
check out the boost format library
http://www.boost.org/libs/format/index.html


Or you could just use printf . . .
Jul 23 '05 #4

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

Similar topics

11
by: Grumble | last post by:
Hello, I have the following structure: struct foo { char *format; /* format string to be used with printf() */ int nparm; /* number of %d specifiers in the format string */ /* 0 <= nparm <=...
8
by: aditya | last post by:
hi, Can anybody please tell me that how the following printf(...) statement works- main(){ int d=9; printf("%d",printf("%d")); return 0;
9
by: Eric Lilja | last post by:
Hello, I have two code snippets I want you to look at. My program compiles without warnings (warning level set to max, gcc 3.4.3) with either snippet but the latter one causes a segfault at...
188
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
29
by: whatluo | last post by:
Hi, c.l.cs I noticed that someone like add (void) before the printf call, like: (void) printf("Timeout\n"); while the others does't. So can someone tell me whether there any gains in adding...
19
by: RedDevilDan | last post by:
I am working on a Memory Footprint Reduction project. I came across an idea to disable all printf statements so that less memory is required. In addition, when there is no single printf statement,...
34
by: Old Wolf | last post by:
Is there any possible situation for printf where %hd causes a different result to %d, and the corresponding argument was of type 'short int' ?
5
by: Sanjay Kulkarni | last post by:
I am facing some problems while trying to explore the printf statement: Expected Actual Result Statement Result 1 printf("x = %d", 18.0 / 14); 18725 5.0 printf("\nx = %f",...
6
by: MikeC | last post by:
Folks, Can the width specifier be used in a printf() text string? If I execute... printf("%4s", ".........."); it prints ten dots. If I execute
11
by: Googy | last post by:
Hi friends!! As we know that the input parameters in a function is fixed when the function is defined but how does printf processes variable number of input arguments ? For example: 1....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.