George Hodgkins
George Hodgkins

Reputation: 89

%F returns no output

I'm writing code to automate writing markup for our web server at work, and I've run into trouble trying to implement an automatic date insertion in the text files using strftime() from the <ctime> header. Here's the relevant code:

if (yen(raw_input))
    {
        time_t rawtime;
        struct tm * timeinfo;
        time (&rawtime);
        timeinfo = localtime (&rawtime);
        strftime(buf, 10, "%F", timeinfo);
        strftime(cuf, 60, "%B %d, %Y", timeinfo);
        date = buf;
        longdate = cuf;
    }
...
ofstream mark;
const string filename = name + date + ".txt";
mark.open(filename);
mark << "{s5_mp3}http://www.####DELETED####.org/media/s5_mp3/" << date << "_" << name_cf << "_Sermon.mp3" << "{\s5_mp3}\n";
mark << hon << " " << name << ": ";
if (is_series) {mark << series << ": ";}
mark << title << "\n";
mark << verse << "\n" << longdate << "\n\0";
mark.close();

The first quoted block inserts today's date in two different format into two already initialized char buffers, and then stores them to strings, and the second section writes everything to a file. date is in format YYYY-MM-DD(%F), and longdate is in format Month DD, YYYY(%B %d, %Y). The problem is that strftime fails to write anything to the char buffer when using %F (determined using debug). If I change %F to the synonymous syntax "%Y-%m-%d", it returns the year and month fine, but the date is two symbols which get boxed out by g++. The perplexing part is that longdate works perfectly, so it's not an issue with timeinfo. Any ideas?

Upvotes: 1

Views: 91

Answers (1)

Khouri Giordano
Khouri Giordano

Reputation: 1461

You should read the standard definition for strftime. Particularly the compatibility section that says %F was:

introduced in C99 (only required for C++ implementations since C++11), and may not be supported by libraries that comply with older standards.

Upvotes: 3

Related Questions