![]() |
|
#1
|
|||
|
|||
display two digit valuesHi
Is there a way to display 2-digit values with cout? |
|
#2
|
||||
|
||||
Re: display two digit valuesNot easily. The simplest is
CPP / C++ / C Code:
cout is notoriously difficult to get formatted output. I find the iomanip flags and features to be tedious and limiting. printf is much better but C++ snobs and zealots don't like using it for some reason. For the hard way, check out this link __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#3
|
||||
|
||||
Re: display two digit valuesQuote:
Please explain more clearly what you want. ![]() Paramesh. PS: Just a joke. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#4
|
|||
|
|||
Re: display two digit valuesWaltP, thx for the link.
Paramesh, I dun really get your joke but.. it's good to joke! |
|
#5
|
||||
|
||||
Re: display two digit valuesQuote:
|
|
#6
|
|||
|
|||
Re: display two digit valuesfirst, sorry I wasn't very clear in the first place.
second, is it really a trivial question? third, what I'm saying is that, if you had a number, say 2, and wanted to display "02", how would you do it with cout? well, WaltP said you can do it like this: CPP / C++ / C Code:
that wasn't very hard. but, what if you wanted to display 2 as "0000000002"?? (a ten-digit number).. that'd be more tedious, not necessarily harder. I hope I've made myself more clear. |
|
#7
|
||||
|
||||
Re: display two digit valuesQuote:
No need to use iomanip! For example, insert this code: CPP / C++ / C Code:
Will print nine '0's before 2. The output will be like: Code:
Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#8
|
||||
|
||||
Re: display two digit valuesQuote:
The printf() function is so much easier and straight forward... __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#9
|
||||
|
||||
The printf/cout challengeI have an ongoing challenge that noone's solved. The challenge is
Convert this printf() statement into readable C++, output must match exactly: CPP / C++ / C Code:
CPP / C++ / C Code:
taken from a previous post __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#10
|
|||
|
|||
Re: The printf/cout challengeQuote:
walts_conjured_up_code.cpp(17) : error C2143: syntax error : missing ';' before 'constant' Ok here you go, CPP / C++ / C Code:
I win. What do I win? Quote:
Quote:
In all seriousness readable is subjective, as is convert, so here you go, CPP / C++ / C Code:
I will not debate whether you have a valid point or not. But most C++ user will use string not *char, so you have deliberately created more problems with your conjured up example than need be. So what you are trying to accomplish. Your gripe seems to be formating. So before you go and start talking about performance and code bulk with what I posted, I am not interested. You should ask the OP if what you posted is more readable. You know the answer will be no. |
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help With Stacks | penance | C Programming Language | 9 | 10-Oct-2005 09:25 |
| fedora display problem | machinated | Computer Software Forum - Linux | 1 | 22-Aug-2005 22:03 |
| problems with a text display in a tab | maveganzones | FLTK Forum | 2 | 23-Mar-2005 03:26 |
| My program can run,but warning were display on Vc++ | fwongmc | C Programming Language | 5 | 08-Dec-2004 11:15 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The