如何在 DevC++ 上显示带有中文字母的行?

How to display lines with Chinese letters on DevC++?

本文关键字:文字 中文 DevC++ 显示      更新时间:2023-10-16

我想要的是显示一行带有中文字母的行,由用户输入。虽然程序DevC ++。

这是我的代码:

#define UNICODE
#include <iostream>
#include <string>
using namespace std;
extern wostream wcout;
int main(int argc, char** argv) {
std::wstring kanji = L"?";
//std::wchar_t stop = L"0";
std::wcout << L"nnWelcome to the Chinese letter programn";
std::wcout << L"The program will ask you for one Chinese lettern";
std::wcout << L"Then press enter, and a message will display.n";
std::wcout << L"Once you are done,you can enter another Chinese lettern";
std::wcout << L"To exit just close the Ubuntu's terminal'nn";
for(int x = 0; x < 80; x++){
std::wcout << L"Give me one Chinese letter...";
wcin >> kanji;
std::wcout << L"The Chinese letter is "" << kanji << "".nn";
}
return 0;
}
对我来说重要的是">

中文字母是"(汉字("这一行。当我按照程序说的去做时,我得到"中文字母是"?所以问题是 DevC++ 没有正确显示中文字母,即使我使用 wcin 和 wcout 的东西也是如此。

注意我在 Ubuntu 上使用 DevC++,通过 wine。

您的控制台是否支持中文编码? 看看这篇文章 如何打印汉字?

这个问题是用html来解决的,它补充了DevC ++无法做的事情,即处理中文字母。

c++ 代码的结尾是这样的:

#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv) {
string kanji = "?";
int x2=0;
int x3=1;
std::cout << "nnWelcome to the Chinese letter programn";
std::cout << "This program will display a line or lines with Chinese lettersn";
std::cout << "through a jury-rigged method.n";
std::cout << "This will generate an html code, that must ben";
std::cout << "transformed into an html file.n";
std::cout << "To exit just close the Ubuntu's terminal.n";
std::cout << "Note: the only catch is that it must be appliedn";
std::cout << "a backspace where you gave enter into the html code.nn";
std::cout << "nnHow many Chinese letters will be?";
cin >> x2;
std::cout << "nn<html>n";
std::cout << "<header><title>Chinese letters</title></header>n";
std::cout << "<body>n";
for(int x = 0; x < x2; x++){
std::cout << "<!-- (Loop " << x3 << "/" << x2 << ") -->n";
std::cout << "The Chinese letter is "";
cin >> kanji;
std::cout << "".n";
std::cout << "<br><br>n";
x3++;
}
std::cout << "</body>n";
std::cout << "</html>n";
std::cout << "nn";
system("pause");
return 0;
}

生成一个可以显示中文字母的html代码。例如像这样:

<html>
<header><title>Chinese letters</title></header>
<body>
<!-- (Loop 1/2) -->
The Chinese letter is "銀".
<br><br>
<!-- (Loop 2/2) -->
The Chinese letter is "囗".
<br><br>
</body>
</html>

以对 c++ 程序的期望结束:

The Chinese letter is "銀".
The Chinese letter is "囗". 

如果不使用陪审团操纵的技巧,就无法在 DevC++ 中做到这一点。所以这个问题是用这种方式解决的,或者用java而不是c++来解决的。

这是代码:

import java.util.Scanner; 
class kanji { 
public static void main(String[] args) { 
Scanner ob = new Scanner(System.in);  
String kanji;
System.out.println("nWelcome to the Chinese letter program");
System.out.println("This program will display one line with a Chinese letter.n");
System.out.println("Which is the Chinese letter?");
kanji = ob.nextLine();
System.out.println("nThe Chinese letter is "" + kanji + "".n");
} //main
} //class

中文字母完全没有问题。

它可以在终端中用"javac -g kanji.java"编译,用"java汉字"执行。