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\pa rse.cpp(98 ) : error C2676: binary '/' : 'class std::basic_string<char,str uct std::char_traits<char>,cla ss std::allocator<char> >' does not define this operator or a conversion to a type acc
eptable to the predefined operator
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\pa
eptable to the predefined operator
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
take that back -- it works now
indegree = atof(degree.c_str())/60.0;
.c_str() -- I dint have that -- what does it do?
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
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*
Dex*
ASKER
C:\Program Files\Microsoft Visual Studio\MyProjects\parse\pa
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.