Solved

string to double

Posted on 2003-12-11
5
827 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:tpiazza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 50 total points
ID: 9922388
@tpiazza:

> indegree = degree/60  

Try this:

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

Hope That Helps,
Dex*
0
 

Author Comment

by:tpiazza
ID: 9922527
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.
0
 

Author Comment

by:tpiazza
ID: 9922539
take that back -- it works now

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

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

0
 
LVL 9

Expert Comment

by:tinchos
ID: 9922578
c_str method

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

Tincho
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9922621
It returns a const char* to the data in the string...  :)

Dex*
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question