我想要的是显示一行由用户输入的中文字母。通过程序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"\n\nWelcome to the Chinese letter program\n";
std::wcout << L"The program will ask you for one Chinese letter\n";
std::wcout << L"Then press enter, and a message will display.\n";
std::wcout << L"Once you are done,you can enter another Chinese letter\n";
std::wcout << L"To exit just close the Ubuntu's terminal'\n\n";
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 << "\".\n\n";
}
return 0;
}对我来说,重要的是“中文字母是”(汉字)。线路。当我按程序说的做时,我得到“中文字母是?”。所以问题是DevC++不能正确显示中文字母,即使我使用wcin和wcout。
请注意,我在Ubuntu上通过wine使用DevC++。
发布于 2020-06-03 11:27:05
您的控制台支持中文编码吗?看看这篇文章How to print a Chinese character?
发布于 2020-06-03 13:46:40
这个问题已经解决了,使用超文本标记语言来补充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 << "\n\nWelcome to the Chinese letter program\n";
std::cout << "This program will display a line or lines with Chinese letters\n";
std::cout << "through a jury-rigged method.\n";
std::cout << "This will generate an html code, that must be\n";
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 applied\n";
std::cout << "a backspace where you gave enter into the html code.\n\n";
std::cout << "\n\nHow many Chinese letters will be?";
cin >> x2;
std::cout << "\n\n<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 << "\n\n";
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 "囗". 发布于 2020-06-12 12:15:03
如果不使用临时操纵的技巧,在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汉字”执行。
https://stackoverflow.com/questions/62164673
复制相似问题