#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
int main()
{
ifstream file1;
file1.open("input.txt");
string str1;
string str2 =str1.substr(12,8);
string str3 = "Max peter 7483289 20174893 2017";
string str4 = str2.substr(12,8); //the position
if(file1.is_open())
{
while(!file1.eof())
{
getline(file1, str1);
if (str2 == str4)
{
cout << "match!";
}
else
{
cout << "In line " << str1 << " there is no a match of: " << str2 << endl;
}
}
}
return 0;
}
when i run the program it is crushing writing "terminate called after throwing an instance of 'std::out_of_range' what<>: basic_string::substr: __pos<which 12> >this ->size() <which is 0> This application has resquested the runtime to terminate it in an unusual way.Please contact the application's support team for more information."