I have the following code:
void readFile(BST *tree) {
ifstream infile("input.txt");
long int sid, t;
string l, f, h;
while (infile >> sid >> l >> f >> h >> t) {
// The line below is for debug purposes
cout << "\"" << sid << "\" \"" << l << "\" \"" << f << "\" \"" << h << "\" \"" << t << "\"" << endl;
tree->insert(sid, l, f, h, t);
}
infile.close();
}
Here is an example line:
78832112 Bruno Nicholas 32_Sugar_Rd_PA_12345 3026821712
Interestingly my code doesn’t read anything from this line. Even more interesting is that if I remove any digit from the last number it reads it just fine.
I have no idea what causes this behavior. Any ideas?
Well, the number is too big for your platform’s
long… you can either useuint64_tor something like that to give your program more breathing space, and/or you have to document your file format and the restriction on the valid ranges of values that your format can support.Never forget that programming is only one half of I/O. The other half is the documentation. I/O is nothing without a format specification.