Andy Ibanez
Andy Ibanez

Reputation: 12254

How Exactly Do I Deal With Japanese Characters in C++?

I'm trying to do something as simple as this:

#include <iostream>
#include <string>
using namespace std;

int main()
{
    wstring nihongo = L"みんなのにほんご";
    wcout << nihongo << endl;
    return 0;
}

But I get the following errors:

C:\Users\Leonne\Leomedia\MetaDatterTest.cpp|7|error: stray '\201' in program|

C:\Users\Leonne\Leomedia\MetaDatterTest.cpp|7|error: stray '@' in program|

C:\Users\Leonne\Leomedia\MetaDatterTest.cpp||In function 'int main()':|

C:\Users\Leonne\Leomedia\MetaDatterTest.cpp|7|error: converting to execution character set: Illegal byte sequence|

||=== Build finished: 3 errors, 0 warnings ===|

I'm in a Windows machine and I am attempting to make a library that is as portable as possible, and it must be able to deal with any kind of characters: Russian, Japanese, ASCII, everything.

Upvotes: 4

Views: 9682

Answers (2)

Shane Powell
Shane Powell

Reputation: 14148

Visual Studio support unicode source files. Make sure that your cpp files are saved a utf16 or utf8 formatted files with a BOM. Once in that format your files will compile fine.

Upvotes: 3

vitakot
vitakot

Reputation: 3844

Check the first answer on this question:

std::wstring VS std::string

and my answer on this:

Handling UTF-8 in C++

I believe you will find there an answer to your question. Troubles with character coding are a bit confusing stuff and there is no simple answer...

Upvotes: 1

Related Questions