954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problem converting to a double

I'm trying this:


char info[50];


myfile.getline(info, sizeof(info) );

double my_double = atof(info);

It seems to work, I think, but I'm getting an error when I try to print out the double. It says no matching function for ostream& << &double.


Can anyone help me with this?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

Sorry, it seemed to be a problem with something else. I fixed it, but it's not recognized my class that should have been imported:

I included the file:

#include "Card.h"


Which is a debitcard class that has some methods. I tried calling one of those methods and it says "implicit declaration of int set_balance(..)"

I called it like this:

set_balance(my_double); That is the signature of the method. Is there something I'm not doing?

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

Can you provide more code? (Also, calling atof for a double maybe a bad idea - losing precision/etc).

winbatch
Posting Pro in Training
466 posts since Feb 2005
Reputation Points: 68
Solved Threads: 18
 

>Also, calling atof for a double maybe a bad idea - losing precision/etc
Calling atof may indeed be a bad idea, but not for the reason you stated. atof returns a double, so the only loss of precision would come from the converted string not representing a value that a double can handle. You should think of the f in atof as "floating-point", not "float".

>set_balance(my_double);
Okay, you're saying that your class isn't recognized, and that the above quote is how you call the member function (aka. method) of the class. So where is the object that you call the member function on? You know, .(args)? It looks more like you're calling a non-member function, and obviously the compiler won't find it.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
Okay, you're saying that your class isn't recognized, and that the above quote is how you call the member function (aka. method) of the class. So where is the object that you call the member function on? You know, .(args)? It looks more like you're calling a non-member function, and obviously the compiler won't find it.

I thought the same thing, but the paper I'm reading from said all I have to do is #include the class and call the method (and the method was in a class). I didn't think that would work, and indeed it didn't. Oh well, I'll create the object like I should have in the first place. Thanks for clearing that up. I'm glad you did, because I was really getting confused with the paper saying/showing I didn't need an object.

server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You