cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
UNIX/Linux Programming
wcstombs is not returning correct output
wcstombs is not returning correct output using g++ compiler
Jul 29, 2009 at 3:14pm UTC
sandyleo
(2)
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;
}
Aug 19, 2009 at 1:44pm UTC
ancest
(6)
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.