Hi all,
Here's the line of code:
-----------------------------------------
int index = 6;
cout << index << endl;
-----------------------------------------
I want it print 06 instead of 6. How do I do it?
thanks.
Hi all,
Here's the line of code:
-----------------------------------------
int index = 6;
cout << index << endl;
-----------------------------------------
I want it print 06 instead of 6. How do I do it?
thanks.
cout<<"0"<<index<<endl;
-Govtcheez
[email protected]
There are other ways than the posted technique, but they aren't as straightforward. If the above is good enough for you so be it. If you want to learn about the alternatives, look up ostream modifiers and manipulators or printf() formatting techniques.
Or...Code:#include <iostream> using namespace std; int main() { int index = 6; cout.fill('0'); cout.width(2); cout << index << endl; return 0; }
Each time you output a value, things will go back to the defaults so you will need to reapply the fill and width commands before each value you are outputting.Code:#include <iostream> #include <iomanip> using namespace std; int main() { int index = 6; cout << setfill('0') << setw(2) << index << endl; return 0; }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
or u could prolly jus say
int var = 06;
cout<<var<<endl;
hooch
Nope, won't work if you do that.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
hmm i guess i should of tested it first
hooch
You would think this is nuclear science...
>>>cout<<"0"<<index<<endl;
nice work govt
Blue
it jus might be nuclear science heh
hooch