Re: confused using swprintf and wstring

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jul 13, 2008 at 2:03 AM, Joel Dice <dicej@xxxxxxxxxxxxx> wrote:
> On Sat, 12 Jul 2008, James Gregory wrote:
>
>> 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?
>
> I think you want "%ls".
>

Ah thanks, you are correct (well, actually it is L"%ls"). Annoyingly
the first google hit for "swprintf" is an example from Microsoft which
does what I was doing.

James

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux