I have a file that contains a set range of numbers for example 20. The contents of the file are social security numbers, I am trying to erase every '-'. Though while going through the file I am receiving a
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string error.
string str;
ifstream inFile (fName);
//fName= name of the file
if (inFile.is_open())
{
while ( getline (inFile,str) )
{
str.erase(3,1);//erasing first '-'
str.erase(5,1);//erasing second '-'
cout << str << endl;
}
inFile.close();
}
else
cout << "Unable to open file";
Aucun commentaire:
Enregistrer un commentaire