I am trying to print the value of a C++ variable in the console for debugging purposes. The line that I am using to try and do this is:
printf("\n Value of lTempCoord in CSARCreepingLineItem::SteerStep(...): %s", rm_WPSequence[m_SAR_OrdinalNumber].m_FixName);
But the output that this line generates is unreadable. I am wondering if this is because I am trying to display it using a 'string' character %s
but then passing something other than a simple string/ character array to it?
Breaking down the variable that I am passing to the printf()
:
rm_WPSequence
is a Vector, defined with:
vector< CUserWaypointListElement > rm_WPSequence;
m_SAR_OrdinalNumber
is an int, and
m_FixName
is a string, defined inside the CUserWaypoingListElement
class with:
std::string m_FixName;
The output generated by the line is a few 'special' characters (not ones that you can see on the keyboard).
What am I doing wrong here? Is the output unreadable because I'm not accessing the member of the Vector
correctly, or because the string
is defined as part of the std
library? Or is it something else completely?
Try this
printf
is basically aC
function, you should usec++
mechanism in yourc++
programs ;). If you really want to useprintf()
, transform yourstd::string
inchar *
by using thestd::string.c_str()
method