-
August 2nd, 2010, 02:31 AM
#1
quick question on strings
Hi Everyone,
Just wondering how can I set the field width during printing. For e.g. how do I print something like the following in C++
printf("%-24s,%-24s %u\n", mystr, myint);
Tx !!
-
August 2nd, 2010, 02:36 AM
#2
Re: quick question on strings
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
August 2nd, 2010, 10:44 AM
#3
Re: quick question on strings
Should be like
Code:
std::cout << std::left << std::setw(24) << mystr
<< ", 0x"
<< std::hex << std::right << std::setw(8) << std::setfill('0') << myint
<< std::endl;
-
August 3rd, 2010, 01:36 AM
#4
Re: quick question on strings
Originally Posted by itsmeandnobodyelse
Should be like
Code:
std::cout << std::left << std::setw(24) << mystr
<< ", 0x"
<< std::hex << std::right << std::setw(8) << std::setfill('0') << myint
<< std::endl;
don't forget the showbase flag/manipulator.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|