#1
Code:
int comma;
...
comma = info.name.find (","); // Search for the comma
if (comma == -1)
cout << "Invalid Data";
else
logon = info.name.substr(0, comma);
Should be:
Code:
string::size_type comma;
...
comma = info.name.find (","); // Search for the comma
if (comma == string::npos)
cout << "Invalid Data";
else
logon = info.name.substr(0, comma);
#2
Code:
while (!fin.fail ())
{
getline (fin, info.name);
getline (fin, info.soc);
...
}
You may need to rethink that loop. The fail will only return true after a read attempt has failed. At the last successful read of data from the file, when there is no more left to read, this will still return true when it's called the very next time. Though there is no more to read from the file, the loop will execute one more time trying to get data that isn't there. The getlines will then set the appropriate error/fail bit for the ifstream object but by that time it's already too late since you're in the loop and processing bad data. The info.name and info.soc variables will likely still contain the results from the previous successful read. Usually, the fix for this is to put the getline call in the while loop's condition test, i.e.:
Code:
while ( getline (fin, info.name) )
{
getline (fin, info.soc);
...
#3
Code:
int ct;
while (...)
{
...
ct++;
}
for (int i =0; i< ct; i++)
Why have ct at all? The vector has a size member function that returns how many elements are stored within it. Just use that. There is no need for a separate variable to keep track of this.
#4
Originally Posted by
jamesnh
i appreciate the help. I found a problem with my getline statements(wasn't stopping at the space).
i was wondering if anyone could give me some insight why this inst working out so well?
Code:
comma = info.name.find (','); // Search for the comma
Don't know, what's the content of the input file look like? Just for grins, what compiler/IDE are you using? MSVC6 has some problems with the getline function.