Archived

This topic is now archived and is closed to further replies.

TheOne1

question on operator

Recommended Posts

TheOne1    156
// Print the time in standard format

void printStandard( const Time &t )
{
	cout << ( ( t.hour == 0 || t.hour == 12 ) ? 12 : t.hour % 12 )
		<< ":" << ( t.minute < 10 ? "0" : "" ) << t.minute
		<< ":" << ( t.second < 10 ? "0" : "" ) << t.second
		<< ( t.hour < 12 ? " AM" : " PM" );
}
I was wondering what happened after the ? 12. If t.hour is == 0 or t.hour == 12, it means to print 12 right? But how does it print 12 when there are no quotes around it so for example "12"? thanks

Share this post


Link to post
Share on other sites
GroZZleR    820
You only put strings within quotes, not numbers.

How would something like the following work, if not?
int iNumber = 5;

Nothing to it:
std::cout << 6 << 24.5f << 1983 << std::endl;

If you''ll notice the last line, where the value is no longer a number, the value is quoted to show a string.

( t.hour < 12 ? " AM" : " PM" );

" AM" and " PM" repesctively.

Good luck in the future!

Share this post


Link to post
Share on other sites