Jackzz
Jackzz

Reputation: 1467

C++: Using %n with strftime

I am developing an application in C++ using VS2010. I tried using the format "%d-%m-%y %n %H:%M:%S" with strfime and I got runtime error telling Debug assert Failed: “Invalid format directive”. On trying to solve the problem, I found that %n is part of C++11 and is not supported by VS2010. So my question is : Is there some other way by which I can have the date and time in two different lines? I have no option to use other versions of VS.

EDIT:

Actually I am using the library wxfreechart to create a graph. Date and time appears in the X-axis. In wxfreechart I have the function SetDateFormat() which accepts date format in strftime style (http://wxcode.sourceforge.net/docs/freechart/classDateAxis.html). My code is actually as follows :

bottomAxis->SetDateFormat(wxT("%d-%m-%y %n %H:%M:%S"));

\n instead of %n gives nothing here.

Sorry for my mistake regarding strftime.

Upvotes: 1

Views: 559

Answers (2)

Jackzz
Jackzz

Reputation: 1467

The problem was not with strftime, but with my usage of wxfreechart. I had to set verticallabeltext to false and then I could use \n as in strftime.

bottomAxis->SetVerticalLabelText(false);
bottomAxis->SetDateFormat(wxT("%d-%m-%y\n%H:%M:%S"));

Upvotes: 0

Ramon van der Werf
Ramon van der Werf

Reputation: 234

Sure, try printing the formatted string "%d-%m-%y \n %H:%M:%S", thus replace "%n" by "\n". In that way it should be working in the older C++ standard, thus in VS2010.

Otherwise you could perhaps you could consider upgrading to a newer version of visual studio.

Here is a good reference :http://www.cplusplus.com/reference/ctime/strftime/

Upvotes: 3

Related Questions