- Feb 15, 2003
- 693
- 0
- 0
I have to write a program for my c++ class and this one part has me stuck. It works for normal integers without decimal points but not for a double. Here is a snippet of code
balanceOwed = currentLine.substr(tempHolder1, tempHolder3);
cout << balanceOwed << endl;
recPtr[recCounter].balanceOwed = atoi(balanceOwed.c_str());
balanceOwed is a string, and currentLine is the line of an input file
the cout statement outputs the string value that I want to be in recPtr.[recCounter].balanceOwed
instead it only does up to the decimal point
ex. cout << balanceOwed; would output 12.44
but after the conversion cout << recPtr[recCounter].balanceOwed would only output 12
I have a feeling the atoi function isnt handling it correctly. Is there a better way to be doing this? I have to be using the getline() function to read my input file. If I have left out any info you may need to assist me let me know. Thanks in advance.
Ben
balanceOwed = currentLine.substr(tempHolder1, tempHolder3);
cout << balanceOwed << endl;
recPtr[recCounter].balanceOwed = atoi(balanceOwed.c_str());
balanceOwed is a string, and currentLine is the line of an input file
the cout statement outputs the string value that I want to be in recPtr.[recCounter].balanceOwed
instead it only does up to the decimal point
ex. cout << balanceOwed; would output 12.44
but after the conversion cout << recPtr[recCounter].balanceOwed would only output 12
I have a feeling the atoi function isnt handling it correctly. Is there a better way to be doing this? I have to be using the getline() function to read my input file. If I have left out any info you may need to assist me let me know. Thanks in advance.
Ben