Problem with gtkmm and c++ class

Hi,
I created calculator class which analyze string and calculates formulas in it.
It works good in terminal. But won't work good in GUI.

If I give to class object string like this "1.3+2.5" in terminal,
it gives result 3.8, but if I give it from GUI. It returns 3.
Can't find why. And it occurs in class method.

Program are over 700 line length, so I can't put in this forum, but if some one wants I can make zip file and put in my site.

outputs:
from gui

1
2
Equation in class: 1.3+2.5
Result in class: 3


from terminal
1
2
Equation in class: 1.3+2.5
Result in class: 3.8
I have found a function where it happens.

1
2
3
4
5
6
7
8
9
10
double Calculator::string_to_double(string line) 
{
	char * c_equation;
	double result;
	c_equation = new char [line.size()];
	strcpy (c_equation, line.c_str());
	result = atof(c_equation);
	delete c_equation;
	return result;
}


this function is a problem. In terminal result is 1.325, but in gui is 1.
Last edited on
maybe your gui doesn't support floating-point numbers! Check it.
How to do it?
I am on Ubuntu and using libgtkmm-3.0-dev 3.3.18-0ubuntu1

And can gui affect c++ program?
Last edited on
viliml umm learn something all modern processors have support for floating points. C/C++ has had support for floating points with some degree of accuracy since their inceptions. He is converting something to string and back and most text or numbers have to be converted to strings to be displayed in a gui.

for example:
1
2
3
4
5
6
7
8
9
10
11
12
13
// converting to float from string:
    string myString = "3.14159";
    stringstream convert;
    convert << myString;
    double myFloat;
    convert >> myFloat;

// converting the float to a string.
    double myFloat = 3.14159;
    stringstream convert;
    convert << myFloat;
    string myString;
    convert >> myString;
Last edited on
In my function Everything goes well until atof() function.
c_equation have full float number as char array.
cout << c_equation[0] << c_equation[1] << c_equation[2] << endl;
have printed good number (1.3), but after atof(c_equation)
result are 1

Azagaros, I will try your code now.

EDIT:
It works. Thanks.
Last edited on
Topic archived. No new replies allowed.