I put together this little example to test my sanity, and it failed!
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
/* Example.txt
23
test
4.5
*/
int main(int argc, char *argv[])
{
string Filename = argv[1];
cout << "Filename: " << Filename << endl;
int Integer;
string String;
double Double;
ifstream fin(Filename.c_str());
string line;
stringstream linestream;
getline(fin, line);
linestream.str("");
linestream << line;
linestream >> Integer;
getline(fin, line);
linestream.str("");
linestream << line;
linestream >> String;
getline(fin, line);
linestream.str("");
linestream << line;
linestream >> Double;
fin.close();
cout << "Integer: " << Integer << endl;
cout << "String: " << String << endl;
cout << "Double: " << Double << endl;
return 0;
}
The output is
Filename: Example.txt
Integer: 65535
String:
Double: 4.86439e-270
Can anyone spot the stupid bug?
Thanks,
Dave