![Quote](https://cboard.cprogramming.com/images/misc/quote_icon.png)
Originally Posted by
jim_0
test1.txt:
Code:
bird=animal
fish=animal
dog=animal
Code:
int i = 0;
while (getline(readfile, str))
{
i = str.find_first_of("=");
if(str.substr(0, i ) == "bird" && str.substr(i, str.length() - i) == "animal"){
//Do Stuff
}
}
I tried this:
Code:
ifstream readfile;
readfile.open("test1.txt");
int i = 0;
string str;
while (getline(readfile, str))
{
i = str.find_first_of("=");
if(str.substr(0, i ) == "bird" && str.substr(i, str.length() - i) == "animal"){
str=str.substr(i, 9);
cout << str << endl;
}
}
But no output either...![Confused](https://cboard.cprogramming.com/images/smilies/confused.png)
What would the str.length() in
Code:
if(str.substr(0, i ) == "bird" && str.substr(i, str.length() - i) == "animal"){
return in this case?