如何在box.get_string()中使用FLTK
How to use of FLTK in-box.get_string()
以下代码是应用程序的一小部分。对于该应用程序,我需要使用in_box.get_string()。in_box的声明和定义位于GUI.h和GUI.cpp文件中的此地址中。
对于整数,它运行良好。也就是说,如果我使用in_box.get_int(),它会获取输入到in _box的数字,并将该数字作为integer
返回。但问题是,它并不像预期的那样适用于strings
。当使用字符串时,我会出错!
例如,在下面的代码中,我使用了string
s。
#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.lib、wsock32.lib和comctl32.libltkjpegd.libltkimages.lib 其次,即使我不认为它会导致链接器错误(但会导致其他奇怪的问题),也要确保您的Visual Studio项目中包含了所有Stroustrup图形库文件:fltk.h、Graph.hUI.h,Window.h、Graph.cpp,GUI.cpp和Windows.cpp
- cppcheck在const std::string[]上引发警告
- 将std::string传递给WriteConsole API
- 为std::string的某个索引赋值
- std中有类似find_last_of的函数,而string中没有
- FLTK:按下哪个按钮 - 将数字传递给按钮的回调 (lambda)
- 使用 std::string () const 函数启动线程或未来
- FLTK 2.0构建和演示,适用于VS2019的2011年左右的代码库
- 使用char类型将decimal转换为string,将string转换为decimal
- 找不到 FLTK(缺少:FLTK_INCLUDE_DIR)
- 迭代和比较映射<字符串、矢量<string>> c++ 中的值
- 当我们进行一些操作时,应该使用什么'std::string'或'std::stringstream'?
- 将向量解析<string>为字符串
- 'string.assign(string.data(), 5)' 是明确定义的还是 UB?
- 如何更改大小(std::string)
- "string.h"在构建适用于iOS的qt应用程序中找不到消息
- C++:如何将 unix 时间的字符串转换为 *tm?(使用时间错误:"cannot convert 'String' to 'tm*' ")
- std::string 的对象真的可以移动吗?
- 与'operator='不匹配(操作数类型'String'且"void")
- SegFault 同时使用 std::string::operator+= 和函数作为参数
- 无法从 std::string 中提取C++ Unicode 符号