我正在用 gtkmm 2 开发一个 C++ 应用程序
我在将字符串从 entryfield 转换为 double(或 int)时遇到问题。
我得到以下编译错误
cannot convert from Glib::ustring to double
输入框
interestrate.set_max_length(50);
interestrate.set_text(interestrate.get_text() );
interestrate.select_region(0, interestrate.get_text_length());
m_box1.pack_start(interestrate);
interestrate.show();
按钮
m_button3.signal_clicked().connect(sigc::bind<-1, Glib::ustring>(
sigc::mem_fun(*this, &HelloWorld::on_button_clicked), "OK"));
m_box1.pack_start(m_button3);
m_button3.show();
和事件处理器
void HelloWorld::on_button_clicked(Glib::ustring data)
{
std::cout << "interestrate: " << interestrate.get_text() << std::endl;
}
所以我想得到双倍的返回值
interestrate.get_text()
最佳答案
没想到这么简单
std::string s = interestrate.get_text();
double d = atof(s.c_str());
关于c++ - 将字符串从 Glib::ustring 转换为 double - gtkm 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24139961/