I am trying to read a .txt file and search for a number that is inside two brackets like this (Inside "Numb[?]")
What I also is doing is to transform all characters to lowercase and this I do inside the while loop. When I do this my program throws an exeption when running.
If I dont use a while loop and would manually put a string to the string Line then this will work.
Why could this happen when I use a while loop.
Code:
#include <ctype.h>
std::string Line;
string stringToFind1 = "Numb[";
while( getline(fin1, Line, '\n') )
{
std::transform(Line.begin(), Line.end(), Line.begin(), ::tolower);
string::size_type startPos = Line.find(stringToFind1);
startPos += stringToFind1.length();
string::size_type endPos = Line.find("]", startPos);
string Number = Line.substr(startPos, endPos - startPos);
if( Line.find(stringToFind1) != string::npos )
{
fout1 << Number;
}
}