What is wrong with this code

Hi guys after doing some research thought I had finally got my program to count html tags correctly. However its not working. When the program is run, it a weird amount for number of tags. The idea I tried was the following
1
2
3
4
5
6
7
if( str.find("<") !=string::npos && str.find(">") != string::npos)
{
    amounttag++;
}
	
      


The if statement is contained in a while loop and the string " str" is declared at the top of the code as string str("<>")

Could someone tell me what's up.

Thanks

Mat
http://www.cplusplus.com/reference/string/string/find.html
may help the examples they have here they use the find out side of the if statement... you might try that

though it works

did you give amounttag a value? cuz i tried it and it didnt work tell i set amounttage to 0;
Perhaps if you showed the entire program it would help. Can there be more than one tag, or trick input? In that case, if a tag is any "<" followed by a ">" it seems your boolean might look more like:
1
2
while ( str.find("<") < string::npos && str.find(">") > str.find("<"))
{   amounttag++;  //then if >1 tags per str, str.assign(...remainder, if any, of str after first ">"...) 

Also, although it is probably overkill for your small app, there's always regular expressions:
http://www.cplusplus.com/forum/beginner/420/

Topic archived. No new replies allowed.