it doesn't contain a double because i'm reading a text file, which i forgot to mention sorry.
my text file has this format:
string, some string, 49.59494, 29.4094944
storing each Field before a comma into the sBuffer[ x ].
so i in fact do have a double. The reason that i think its not working is that the complier is interpreting it as a string, or char, and not a double value.
right?
Heres my full code feel free to compile in dev or something but be sure to use the text file with this format:
String,Some String,54.2345,34.6654
...
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main()
{
string usrFileStr,
fileStr = "test.txt", // declaring an obj string literal
sLine, // declaring a string obj
sBuffer;
int lineCount = 1;
fstream inFile; // declaring a fstream obj
// cout is the name of the output stream
cout << "Enter a file: ";
cin >> usrFileStr;
inFile.open( usrFileStr.c_str(), ios::in );
// at this point the file is open and we may parse the contents of it
while ( getline ( inFile, sBuffer ) && !inFile.eof() )
{
int nStart = -1 ;
cout << "First String " << lineCount << " (";
for ( int x = nStart + 1; x < sBuffer.length(); x++ )
{
if ( sBuffer[ x ] == ',' )
{
nStart = x;
break;
}
cout << sBuffer[ x ];
}
cout << ") ";
for ( int x = nStart + 1; x < sBuffer.length(); x++ )
{
if ( sBuffer[ x ] == ',' )
{
nStart = x;
break;
}
cout << sBuffer[ x ];
}
cout << " (First dValue";
for ( int x = nStart + 1; x < sBuffer.length(); x++ )
{
if ( sBuffer[ x ] == ',' )
{
nStart = x;
break;
}
cout << setprecision(2) << sBuffer[ x ];
}
cout << ", Second dValue: ";
for ( int x = nStart + 1; x < sBuffer.length(); x++ )
{
if ( sBuffer[ x ] == ',' )
{
nStart = x;
break;
}
cout << sBuffer[ x ];
}
cout << ") \n";
lineCount++;
}
cout << "There are a Total of: " << lineCount << " line(s) in the file."
<< endl;
inFile.clear(); // clear the file of any errors
inFile.close(); // at this point we are done with the file and we close it
fgetc( stdin );
return 0;
}
// use a funnction
Yeah i know i could use a function prototype for the excessive looping(4)
But i'd like to get this value issue taken care of first.