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
    21,717
    if t.hour < 10, then the expression has the value of "0", otherwise it has the value of "".
    zafar hashmi likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,717
    It just means that t is a const reference parameter, i.e., of type const Time&.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,625
    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,407
    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