By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,538 IT Pros & Developers. It's quick & easy.

wstring usage

P: n/a
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,
std::char_traits<wchar_t>, std::allocator<wchar_t>
>::basic_string(const
char[4])'
Thanks in Advance
Kiran Pradeep

Oct 26 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
wolverine wrote:
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,
std::char_traits<wchar_t>, std::allocator<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.
Oct 26 '06 #2

P: n/a
wolverine wrote:
#include<iostream>
#include<string>
using namespace std;

int main()
{
std::wstring str("ABC");
Try:

std::wstring str(L"ABC");
return 0;
BTW: return 0; is redundant here.
}

Best

Kai-Uwe Bux
Oct 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.