FLTK 中文显示乱码解决方法

偶然使用FLTK时发现中文乱码

中文按钮乱码

解决方法

直接从编译器入手,在代码中添加一行

#pragma execution_character_set("utf-8")

看!不乱码了吧
中文显示
顺便把源码放在这里,有需要的朋友们可以自取:

#include <iostream>
#include <string>
#include <FL/Fl.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Repeat_Button.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

#pragma execution_character_set("utf-8")

using namespace std;

namespace Examples {
    class Main_Window : public Fl_Window {
    public:
        Main_Window() : Fl_Window{ 200, 100, 800, 600, "Button example" } {
            button1.align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP | FL_ALIGN_WRAP);
            button1.callback([](Fl_Widget* sender, void* window) {
                auto result = "Button 1 点击 " + to_string(++reinterpret_cast<Main_Window*>(window)->button1_clicked) + " times";
                reinterpret_cast<Main_Window*>(window)->box1.copy_label(result.c_str());
                }, this);

            button2.align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP | FL_ALIGN_WRAP);
            button2.callback([](Fl_Widget* sender, void* window) {
                auto result = "Button 2 点击 " + to_string(++reinterpret_cast<Main_Window*>(window)->button2_clicked) + " times";
                reinterpret_cast<Main_Window*>(window)->box2.copy_label(result.c_str());
                }, this);

            box1.align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
            box2.align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
        }

    private:
        Fl_Button button1{ 50, 50, 75, 25, "按钮 1" };
        Fl_Repeat_Button button2{ 50, 100, 200, 75, "按钮 2" };
        Fl_Box box1{ 50, 200, 200, 20, "Button 1 clicked 0 times" };
        Fl_Box box2{ 50, 230, 200, 25, "Button 2 clicked 0 times" };
        int button1_clicked = 0;
        int button2_clicked = 0;
    };
}

auto main(int argc, char* argv[]) -> int {
    Examples::Main_Window window;
    window.resizable(&window);
    window.show(argc, argv);
    return Fl::run();
}

最后我要说一句,what the fuck构式CSDN,sb的流氓网页设计!!!

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值