By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,538 Members | 875 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.

string to wstring problem

P: n/a
1. Why the following program is not working as expected?

#include <iostream>
using namespace std;

int main()
{
string t("test");
wcout << (wchar_t *) t.c_str() << endl;
wcout << t.c_str() << endl;

wstring t2 = (wchar_t *) t.c_str();
wcout << t2.c_str() << endl;

return 0;
}
2. It is acceptable that there is no conversion from wstring to
string, but,
Why there is no conversion (wstring::wstring(string )) from string to
wstring? Even, there is no string member function like, wc_str() that
returns "wchar_t *" ?!

3. How a simple string can be converted to wstring?

Apr 25 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
v4vijayakumar skrev:
1. Why the following program is not working as expected?

#include <iostream>
using namespace std;

int main()
{
string t("test");
wcout << (wchar_t *) t.c_str() << endl;
wcout << t.c_str() << endl;

wstring t2 = (wchar_t *) t.c_str();
wcout << t2.c_str() << endl;

return 0;
}
2. It is acceptable that there is no conversion from wstring to
string, but,
Why there is no conversion (wstring::wstring(string )) from string to
wstring? Even, there is no string member function like, wc_str() that
returns "wchar_t *" ?!

3. How a simple string can be converted to wstring?
Consider,

char c = /* some value */;

wchar_t wc = c;

What exactly is 'wc' supposed to contain? What do you expect the
value to be? It's internal format?

--
OU
Apr 25 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.