如何在box.get_string()中使用FLTK

How to use of FLTK in-box.get_string()

本文关键字:FLTK string box get      更新时间:2023-10-16

以下代码是应用程序的一小部分。对于该应用程序,我需要使用in_box.get_string()。in_box的声明和定义位于GUI.hGUI.cpp文件中的此地址中。

对于整数,它运行良好。也就是说,如果我使用in_box.get_int(),它会获取输入到in _box的数字,并将该数字作为integer返回。但问题是,它并不像预期的那样适用于strings。当使用字符串时,我会出错!

例如,在下面的代码中,我使用了strings

#include <GUI.h>
#include <iostream>
using namespace Graph_lib;
class Calculator : public Window {
public:
    Calculator(Point, int, int, const string&);
private:
    //Widgets
    Button show_button;
    In_box enter_box;
    void show() { getstr(); cout <<s; }
    void getstr() {
        s = enter_box.get_string();
    }
  static void cb_show(Address, Address pw) { reference_to<Calculator>(pw).show(); }
  string s;
};
//---------------------------------------------------------------------
Calculator::Calculator(Point xy, int w, int h, const string& title):
    Window(xy, w, h, title),
    show_button(Point(x_max()-110, 440), 90, 35, "Show", cb_show),
    enter_box(Point(x_max()-400, 158), 245, 40,  "Enter"){
    attach(enter_box);
    attach(show_button);
}
int main()
{
    Calculator cal(Point(100,100), 600, 500, "Calculator");
    return gui_main();
}

有8个警告和两个error。错误如下:

错误9错误LNK2019:未解析的外部符号"public:class std::basic_string,classstd::分配器>__thiscall Graph_lib::In_box::get_string(void)"(?get_string@In_box@Graph_lib@@QAE?AV$basic_string@DU$char_traits@D@std@@V$allocator@D@2@@std@@XZ)在函数"private:void __thiscall"中引用计算器::getstr(void)"(?getstr@Calculator@@AAEXXZ)C:\Users\ME\documents\visual studio2012\Projects\test_3\test_3\test.3.obj错误10错误LNK1120:1未解析的外部文件C:\Users\ME\documents\visual studio2012\Projects\test_3\Debug\test_3.exe

错误表明,这是一个链接器问题,但我的链接器输入的文件列表如下,到目前为止(几乎)工作良好。

fltkd.lib
wsock32.lib
comctl32.lib
fltkjpegd.lib
fltkimagesd.lib

我的编译器是MS VS 2012。这台机器就是Win 7。

有人知道如何解决这个问题吗?

如果您在调试和发布模式下编译了FLTK,请确保您拥有正确的链接器依赖项:为调试列出的文件,以及为发布列出的FLTK.libwsock32.libcomctl32.libltkjpegd.libltkimages.lib

其次,即使我不认为它会导致链接器错误(但会导致其他奇怪的问题),也要确保您的Visual Studio项目中包含了所有Stroustrup图形库文件:fltk.hGraph.hUI.hWindow.hGraph.cppGUI.cppWindows.cpp