C++, strptime(), POSIX_LOCALE - IBM AS400

This is a discussion on C++, strptime(), POSIX_LOCALE - IBM AS400 ; I'm trying to get a small test program to compile using the strptime() function. The compile fails because it can't see the definition in p_time.h. The only reason I can see this is happening is because the macro __POSIX_LOCALE__ must ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: C++, strptime(), POSIX_LOCALE

  1. C++, strptime(), POSIX_LOCALE

    I'm trying to get a small test program to compile using the strptime()
    function. The compile fails because it can't see the definition in
    p_time.h. The only reason I can see this is happening is because the
    macro __POSIX_LOCALE__ must not be defined. p_time.h has an #ifdef
    for this definition. The AS/400 C says this macro will be one when
    LOCALTYPE(*LOCALE) is specified but this is on by default on the C++
    compiler. I'm using V6R1.

    #include
    #include
    #include
    #include
    #include


    using namespace std;


    int main(int argc, char *argv[])
    {
    char *timeStr = "2008-09-15-18.46.40.000000", *p;
    struct tm tm;
    time_t theTime, currentTime;


    p = strptime(timeStr, "%Y-%m-%d-%H.%M.%S", &tm);
    if (p) {
    printf("%s\n", p);
    }
    theTime = mktime(&tm);
    currentTime = time(0);

    if (currentTime > theTime) {
    cout << "expired" << endl;
    }
    }

  2. Re: C++, strptime(), POSIX_LOCALE

    The p_time.h header file is a non-standard header file and is not
    meant to be directly included. All you need to do is remove the
    include of p_time.h from the example code above. When
    __POSIX_LOCALE__ is defined time.h will include p_time.h and
    everything will work as expected.

+ Reply to Thread