I ran into such a problem: i wrote some code and when i try to format some data (especially strings) i got strange result
#include <iostream> // std::cout, std::endl
#include <string.h>
#include <vector>
#include <cstdarg>
#include <sstream>
using namespace std;
void va_cout(string format, ...)
{
vector<char> buf(256);
va_list args;
va_start(args, format);
vsnprintf_s(&buf[0], buf.size(), buf.size() + strlen(format.c_str()), format.c_str(), args);
va_end(args);
cout << endl << "apply va_cout(""%s"", s) = " << &buf[0] << endl;
}
int main() {
string s("myString");
cout << endl << s << endl;
va_cout("%s", s);
va_cout("%s", s.c_str());
return 0;
}
// results
myString
apply va_cout(%s, s) = └¤#
apply va_cout(%s, s) = myString
why it returns line 2 ?