wstring usage

W

wolverine

Hi
Could any one tell me how to compile the code using wstring with
g++ or gcc. I am using gcc version 3.4.2

#include<iostream>
#include<string>
using namespace std;

int main()
{
std::wstring str("ABC");
return 0;
}

This is the error message i got when i compiled the code

g++ program.cpp
wstring.cpp:7: no matching function for call to
`std::basic_string<wchar_t,
::basic_string(const
char[4])'


Thanks in Advance
Kiran Pradeep
 
P

Pete Becker

wolverine said:
std::wstring str("ABC");

std::wstring str(L"ABC");
This is the error message i got when i compiled the code

g++ program.cpp
wstring.cpp:7: no matching function for call to
`std::basic_string<wchar_t,
::basic_string(const
char[4])'

There's no wstring constructor that takes narrow characters. Doing that
would require mapping the narrow characters to wide, which requires a
locale. basic_string doesn't deal in locales, so for wstring you have to
pass in wide characters.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top