简体   繁体   English

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

[英]How to display lines with Chinese letters on DevC++?

What I want is to display a line with a Chinese letter, entered by the user.我想要的是显示用户输入的带有中文字母的行。 Though the program DevC++.虽然程序 DevC++。

This is my code:这是我的代码:

#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;
}

What matters to me is the "The Chinese letter is "(kanji)"."对我来说重要的是“中文字母是“(汉字)”。 line.线。 When I do what the program says I get "The Chinese letter is "?".".当我按照程序说的做时,我得到“中文字母是“?”。 So the problem is that DevC++ doesn't show the Chinese letters correctly, even when I using the wcin and wcout things.所以问题是 DevC++ 没有正确显示中文字母,即使我使用 wcin 和 wcout 的东西。

Note I am using DevC++ on Ubuntu, through wine.注意我通过 wine 在 Ubuntu 上使用 DevC++。

Do your console support Chinese encoding?你的控制台支持中文编码吗? take a look at this post How to print a Chinese character?看看这篇文章如何打印一个汉字?

The problem was solved using html to complement what DevC++ cannot do, which is working with Chinese letters.使用 html 解决了该问题,以补充 DevC++ 无法使用中文字母的功能。

The c++ code ended up like this: 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;
}

Which generates an html code that can display Chinese letters.生成一个可以显示中文字母的html码。 For example like this:例如像这样:

<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>

Ending with what was expected from the c++ program:以 c++ 程序的预期结束:

The Chinese letter is "銀".

The Chinese letter is "囗". 

That cannot be done in DevC++ without using jury-rigged tricks.如果不使用陪审团操纵的技巧,在 DevC++ 中就无法做到这一点。 So the problem was solved using that way or using java instead of c++.因此,使用这种方式或使用 java 而不是 c++ 解决了问题。

Here is the code:这是代码:

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

Having no problems at all with the Chinese letters.中文字母完全没有问题。

It can be compiled in the terminal with "javac -g kanji.java", and executed with "java kanji".可以在终端用“javac -g kanji.java”编译,用“java kanji”执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM