Search code examples
c++visual-studio-2010c++11wxwidgetsstrftime

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.


Solution

  • 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/