Jump to content
  • Advertisement

Archived

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

TheOne1

question on operator

This topic is 5321 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
Advertisement
Because the ostream::operator<<() is overloaded to output all the basic types. There''s no problem in doing cout << 12;

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!