Link to home
Start Free TrialLog in
Avatar of tpiazza
tpiazza

asked on

string to double

i get a string from a line I'm parsing.

string notdegree= buf[2];    returns a number but its a string

string degree=  notdegree.substr(0,5); returns the part of the number i want still a string

         indegree = degree/60  -- i need to be able to do this  -- how do I change something from a string to a number

the following is the error i get

C:\Program Files\Microsoft Visual Studio\MyProjects\parse\parse.cpp(98) : error C2676: binary '/' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acc
eptable to the predefined operator
ASKER CERTIFIED SOLUTION
Avatar of Dexstar
Dexstar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tpiazza
tpiazza

ASKER

tried that it errors out

C:\Program Files\Microsoft Visual Studio\MyProjects\parse\parse.cpp(100) : error C2664: 'atof' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.
Avatar of tpiazza

ASKER

take that back -- it works now

indegree = atof(degree.c_str())/60.0;

.c_str() -- I dint have that -- what does it do?

c_str method

Returns a pointer to a null-terminated array of characters representing the string's contents.

Tincho
It returns a const char* to the data in the string...  :)

Dex*