* confused using swprintf and wstring
@ 2008-07-12 23:13 James Gregory
2008-07-13 6:07 ` Joel Dice
0 siblings, 1 reply; 3+ messages in thread
From: James Gregory @ 2008-07-12 23:13 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: confused using swprintf and wstring
2008-07-12 23:13 confused using swprintf and wstring James Gregory
@ 2008-07-13 6:07 ` Joel Dice
2008-07-13 21:29 ` James Gregory
0 siblings, 1 reply; 3+ messages in thread
From: Joel Dice @ 2008-07-13 6:07 UTC (permalink / raw)
To: James Gregory; +Cc: gcc-help
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".
>
> Thanks,
>
> James
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: confused using swprintf and wstring
2008-07-13 6:07 ` Joel Dice
@ 2008-07-13 21:29 ` James Gregory
0 siblings, 0 replies; 3+ messages in thread
From: James Gregory @ 2008-07-13 21:29 UTC (permalink / raw)
To: Joel Dice; +Cc: gcc-help
On Sun, Jul 13, 2008 at 2:03 AM, Joel Dice <dicej@mailsnare.net> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-13 9:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-12 23:13 confused using swprintf and wstring James Gregory
2008-07-13 6:07 ` Joel Dice
2008-07-13 21:29 ` James Gregory
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).