A
Allen
Hi, I am transporting a c++ program from win32 to ibm aix 5.3.
There is a file name Measurement.cpp which contains some string, for
example:
static std::wstring breaker = L"开关";
The Measurement.cpp is encoding in UTF-8;
The transporting procedure is as following:
1.change Measurement.cpp encoding type to be GB18030 as aix 5.3
needed.
2.write a subfunction name ws2s:
std::string ws2s(const std::wstring & src) {
const int dsize = 2 * src.size() + 1;
char * buff = new char[dsize];
memset(buff, 0, dsize);
setlocale(LC_ALL, "");
wcstombs(buff, src.c_str(), dsize);
setlocale(LC_ALL, "C");
std::string result = buff;
delete[] buff;
buff = NULL;
return result;
}
3.output the breaker
std::cout << ws2s(breaker) << std::endl;
But the output text is not correctly display.
Would you please help me? Thank you.
There is a file name Measurement.cpp which contains some string, for
example:
static std::wstring breaker = L"开关";
The Measurement.cpp is encoding in UTF-8;
The transporting procedure is as following:
1.change Measurement.cpp encoding type to be GB18030 as aix 5.3
needed.
2.write a subfunction name ws2s:
std::string ws2s(const std::wstring & src) {
const int dsize = 2 * src.size() + 1;
char * buff = new char[dsize];
memset(buff, 0, dsize);
setlocale(LC_ALL, "");
wcstombs(buff, src.c_str(), dsize);
setlocale(LC_ALL, "C");
std::string result = buff;
delete[] buff;
buff = NULL;
return result;
}
3.output the breaker
std::cout << ws2s(breaker) << std::endl;
But the output text is not correctly display.
Would you please help me? Thank you.