[英]error in c++ unicode program using MinGW
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
wstring str = L"こんにちは";
wcout<<str<<endl;
system("pause");
}
我正在嘗試從C ++程序打印日語(hello),但出現錯誤。 我已經使用UNICODE編碼將該程序保存在記事本中,然后使用MinGW 4.7.2編譯,並出現以下錯誤:
E:\GCC test>g++ -c unicode.cpp
unicode.cpp:1:1: error: stray '\377' in program
unicode.cpp:1:1: error: stray '\376' in program
unicode.cpp:1:1: error: stray '#' in program
unicode.cpp:3:4: error: invalid preprocessing directive #i
unicode.cpp:5:4: error: invalid preprocessing directive #i
unicode.cpp:1:5: error: 'i' does not name a type
unicode.cpp:11:2: error: 'i' does not name a type
到了錯誤,它看起來像你有在UTF-16LE有一個文件BOM (B YTE 即刻申中號櫃),以及編譯器不喜歡這樣。
\\377\\376
= 0xfffe
=一個UTF-16LE BOM
嘗試刪除BOM表,和/或嘗試使用其他編碼。 UTF-8是一種出色的編碼,不需要BOM,大多數編譯器和許多其他工具都可以理解。
至於Unicode ,它不是二進制字符編碼。 但是,有一些編碼“綁定”到Unicode。 UTF-8和UTF-16可能是最常見的此類編碼。
如果編輯器提供以“ Unicode編碼”保存文件,請嘗試遠離該編輯器。 如果該編輯器是記事本,那么還有更多理由不要使用它。 為自己准備一個合適的編程編輯器,他能理解編碼和EOL,並具有語法突出顯示等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.