string to wstring problem

V

v4vijayakumar

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?
 
O

Obnoxious User

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?
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top