944,092 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1444
  • C RSS
Jan 19th, 2006
0

Problem converting to a double

Expand Post »
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?
Similar Threads
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jan 19th, 2006
0

Re: Problem converting to a double

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?
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jan 19th, 2006
0

Re: Problem converting to a double

Can you provide more code? (Also, calling atof for a double maybe a bad idea - losing precision/etc).
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Jan 20th, 2006
0

Re: Problem converting to a double

>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, <object>.<member function>(args)? It looks more like you're calling a non-member function, and obviously the compiler won't find it.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jan 20th, 2006
0

Re: Problem converting to a double

Quote originally posted by Narue ...
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, <object>.<member function>(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.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: (C) have 2 parse errors (help)
Next Thread in C Forum Timeline: Serialize/MFC Question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC