confused using swprintf and wstring

James Gregory james.jrg@gmail.com
Sat Jul 12 23:13:00 GMT 2008


Here is my little test program:

#include <iostream>
#include <wchar.h>
#include <string>

using std::wcout;
using std::wstring;
using std::endl;

int main(char** argv, int argc) {
	wstring s = L"blah";
	wchar_t o[50];
	swprintf(o, 50, L"%s", s.c_str());
	wcout << o << endl;
}

I would expect it to produce write "blah" on the standard output, but
instead it writes "b". Why is this?

Thanks,

James



More information about the Gcc-help mailing list