So I'm working with time.h for this (copied from msdn):

int main( void )
{
        struct tm newtime;
        char am_pm[] = "AM";
        __time64_t long_time;
        char timebuf[26];
        errno_t err;

        // Get time as 64-bit integer.
        _time64( &long_time ); 
        // Convert to local time.
        err = _localtime64_s( &newtime, &long_time ); 
        if (err)
        {
            printf("Invalid argument to _localtime64_s.");
            exit(1);
        }
        if( newtime.tm_hour > 12 )        // Set up extension. 
                strcpy_s( am_pm, sizeof(am_pm), "PM" );
        if( newtime.tm_hour > 12 )        // Convert from 24-hour 
                newtime.tm_hour -= 12;    // to 12-hour clock. 
        if( newtime.tm_hour == 0 )        // Set hour to 12 if midnight.
                newtime.tm_hour = 12;

        // Convert to an ASCII representation. 
        err = asctime_s(timebuf, 26, &newtime);
        if (err)
        {
           printf("Invalid argument to asctime_s.");
           exit(1);
        }
        printf( "%.19s %s\n", timebuf, am_pm );
}

when i notice the printf lines. Well, ive been using cout this whole project and wanted to know if anyone can help me with a switch-over for it.

Member Avatar for TheFearful

I assume you want get rid of printf and use cout instead?
cout works very similar to printf, except the semantics are slightly different

cout << "string" << (whatever integer you are using) << endl;//if you want to create a new line

The << is like the , in printf.
I did a poor explanation, but hopefully this helps clarify things a bit.

cout cannot "replace" printf because printf has formatting flags.. cout does not.

You would have to use a modifier or sprintf to a buffer then print the buffer using cout.

Modifiers such as std::setprecision would suffice. If you are sure you only want to print 19 characters max, then std::cout.write(time_buff, 19); would also do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.