Archived

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

question on operator

This topic is 5008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

// 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
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