What does this error mean? I singled it down the me using string.substr(), but i dont see the error. I put a small snippet up testing that for an error, but i get the expected results with:
1 2 3 4 5 6 7 8 9
#include <iostream>
#include <vector>
#include <string>
int main(){
std::string s = "t t print('tester')";
int ind = s.find("print");
std::cout << ind << std::endl;
std::cout << s.substr(ind) << std::endl;
}
which prints out:
1 2
4
print('tester')
and te last line being what i expected from the other code
I am not sure whats different from this code snippet and this code?
if (line.find("print")){
ind = line.find("print");
std::cout << line.substr(ind);
}
is invalid. If find does not find a string it retursn non-sero value. So this condition if (line.find("print")) will be equal to true. The correct if statement will look as
1 2 3 4
if (line.find("print") != std::string::npos ){
ind = line.find("print");
std::cout << line.substr(ind);
}