我正在使用带有C ++的gtkmm,但我遇到了问题。这是我的代码:
#include <gtkmm/box.h>
#include <gtkmm/entry.h>
#include <gtkmm/main.h>
#include <gtkmm/window.h>
int main(int argc, char* argv[]) {
Gtk::Main app(argc, argv);
Gtk::Window window;
Gtk::VBox boxv(false, 10);
Gtk::Entry entry1;
boxv.pack_start(entry1);
Gtk::Entry entry2;
boxv.pack_start(entry2);
entry1.signal_activate().connect([&entry2, &entry1](){
std::string a = entry1.get_text();
double c = std::atof(a.c_str());
c = 45*c;
std::string s;{
std::ostringstream oss;
oss << c;
s = oss.str();
}
entry2.set_text(s);
});
window.add(boxv);
window.show_all();
Gtk::Main::run(window);
return 0;
}
问题是:当我输入entry1例如10时,我得到45 * 10。如果我输入10.20,我也会得到45 * 10而不是45 * 10.20。我尝试输入10,20,在这种情况下,我得到45 * 10,20,但我想使用。代替 , 你有解决方案吗?
非常感谢!!!!
答案 0 :(得分:5)
听起来您的 locale 设置为小数点分隔符为,
的。要强制.
作为分隔符,您可以将数字区域设置为C:
#include <clocale>
//...
setlocale(LC_NUMERIC, "C");
在使用atof
之前。