wcstombs is not returning correct output using g++ compiler

Kindly have a look at following code piece:

When I am compiling this code on Visual studio compiler, I am getting correct output "こんにちは、お元気です"in abc variable. But, I am facing issue when I tried to compile the same code on linux (g++ compiler). Output string gets corrupted.

Please let me know where I am doing mistake.



#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <locale>
using namespace std ;

int main()
{
int i;
setlocale(LC_ALL,"japanese");
char* abc = (char*)malloc(500);
wchar_t* wabc = L"こんにちは、お元気です";
i = wcstombs(abc, wabc, 500);
cout<<i<<endl;
cout<<abc<<endl;
}



Hai i tried this in my fedora-8 and i get the correct output by changing line " setlocale(LC_ALL,"japanese"); "

to

setlocale(LC_ALL,"");

And i am getting the correct output. I dont know the actual reason for why it is so but it is working.Try it.
Topic archived. No new replies allowed.