Like Tree1Likes
  • 1 Post By laserlight

( t.hour < 10 ? "0" : "" ) << t.hour << ":" meaning.

This is a discussion on ( t.hour < 10 ? "0" : "" ) << t.hour << ":" meaning. within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm a new C++ user. I dont know what does this mean. Code: void printMilitary( const Time &t ) ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    102

    ( t.hour < 10 ? "0" : "" ) << t.hour << ":" meaning.

    Hi,
    I'm a new C++ user. I dont know what does this mean.

    Code:
    void printMilitary( const Time &t ) <---what does Time &t means?
    {
       cout << ( t.hour < 10 ? "0" : "" ) << t.hour << ":"
            << ( t.minute < 10 ? "0" : "" ) << t.minute;
    }
    ( t.hour < 10 ? "0" : "" ) a bit of weird to me. WHat does it mean?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    if t.hour < 10, then the expression has the value of "0", otherwise it has the value of "".
    zafar hashmi likes this.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2011
    Posts
    102
    ok thanks, Then again. is const Time &t means - Type time of L-value of T which is a const?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    It just means that t is a const reference parameter, i.e., of type const Time&.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Aug 2011
    Posts
    102
    Thanks again. Do you type wrong or something......type const Time&. Why & is at the back?

  6. #6
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,836
    Quote Originally Posted by ncode View Post
    Thanks again. Do you type wrong or something......type const Time&. Why & is at the back?
    All together it's a constant reference. We usually pass structs by reference because they're big, but in case we try to accidentally alter them we add const.
    Devoted my life to programming...

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    2,862
    where the '&' goes is entirely up to you.

    Code:
    void printMilitary( const Time &t )
    is exactly the same as
    Code:
    void printMilitary( const Time& t )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-31-2009, 04:23 PM
  2. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  3. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21