如何在 DevC++ 上显示带有中文字母的行?
How to display lines with Chinese letters on DevC++?
我想要的是显示一行带有中文字母的行,由用户输入。虽然程序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汉字"执行。
相关文章:
- constexpr 函数中的非文字(通过 std::is_constant_evaluated)
- 我可以使用条件运算符初始化C风格的字符串文字吗
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- 如何使用字符串文字作为宏参数
- 有没有办法从非C/C++文件中读取C++原始字符串文字的内容
- 构造<int>具有 2 个字符串文字的向量
- 将数字打印成文字
- 初始化或分配空字符串文字到指向 C 中的 char 的指针或指向 C++ 中 const char 的指针的原因是什么
- 方便地对C++中的所有字符串文字进行模糊处理
- C++17 十六进制浮点文字单精度后缀冲突?
- 常量函数,当其参数是对文字类型的引用时
- 连接 LPCSTR 变量和文字?
- 如何在 DevC++ 上显示带有中文字母的行?
- 比较 std::string 和 C 样式字符串文字
- 如何从char16_t字符串文字中读取双精度?
- 指内置类型的文字
- 分配给浮点数的积分文字除法 - 为什么结果是错误的?
- std::remove() 按预期处理文字,但不能与取消引用的迭代器一起工作
- 为什么带有指针子对象的文字类类型的 constexpr 表达式不能是非类型模板参数
- 为什么文字不是常量(字符串除外)?