Solved

string to double

Posted on 2003-12-11
5
780 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
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
Dexstar earned 50 total points
Comment Utility
@tpiazza:

> indegree = degree/60  

Try this:

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

Hope That Helps,
Dex*
0
 

Author Comment

by:tpiazza
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
It returns a const char* to the data in the string...  :)

Dex*
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now