find does not seem to work properly with "</table>"

I have a program which searches throughout a html file line by line.

I know that in the html file there is a one time mention of "</table>" and I want to know in which line of the html document it is placed.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
#include <string>
using namespace std:

int main(){
        string line;
	ifstream endfile ("sourcecode.html");
	while(getline (endfile,line)){
		size_t found=line.find("</table");
		if (found=string::npos){
			cout << found; //test
			break;
		}
	}
        return 0;
}

Cout is 3, should be rather 263X.
So I assume that the code does not search for "</table>" correctly and stops somewhere before. Where is my mistake?

The site I want the "</table> from:
http://animexx.onlinewelten.com/aidb/manga-deutschland.phtml?modus=ankuendigungen
Look at this snippet:
1
2
3
4
		if (found=string::npos){
			cout << found; //test
			break;
		}

First if found is equal to std::string::npos then the value was not found. Also do you know the difference between the operator= and the operator==?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    int count;
    string line;
	ifstream endfile ("sourcecode.html");

    while(getline (endfile,line))
    {

        size_t found = 0;
        found = line.find("</table",0);

        if(found == _UI64_MAX)
        {
            count += 1;
        }

        if (found != string::npos)
        {
            cout << "</table located at line " << count +1 << endl;
        }
    }
        return 0;
}

@jlb
I know the difference, I just made a mistake copy pasting, sorry! ;).

@rafae11
I took your suggestion, just modified it a bit to make it work without _UI64_MAX.

1
2
3
4
5
6
7
8
9
10
11
        int count=0;
        int temp_found=0;
	while(getline (endfile,line)){
	        size_t found = line.find("</table",0);
			count += 1;
	        if (found != string::npos){
			temp_found=count;
                        break;
        	}
	}
	endfile.close();
Topic archived. No new replies allowed.