I am not quite expert in C++ and I am writing a program to read multiple URL's on a single line of a html file, so I wrote this code:
ifstream bf;
short chapters=0;
string blkhtml;
string blktmpfile; //given
string urldown; //given
size_t found = 0, limit;
while(getline(bf, blkhtml)){
while((blkhtml.find(urldown, found) != string::npos) == 1){
found = blkhtml.find(urldown);
limit = blkhtml.find("\"", found);
found=limit + 1;
chapters++;
}
}
My problem here is that found is not updated to be used in the while condition. As I've seen, std::string classes aren't updated unless another std::string class (for a string, str.erase() updates it's value, but (str.at() = '') doesn't), What can I do here if I want "found" to be updated every time the loop begins, and for the condition.
What I want to do is:
Check if there is a coincident expression for the
urldowngiven string.Set it's first and last character.
Update 'pos' in the loop after the found url, and then look for the next.
I've looke all over cplusplus.com and cppreference.com and I haven't found something that helps me.
I thought about std::list::remove on a loop with every number from 0 to 9, and then give it a new value, but I don't know if it is the best option.
blkhtml.find(urldown, found), but you updatefoundwithblkhtml.find(urldown). Can you spot the difference?urldown, then I use found and limit to go to the end of that url. As limit is the end,found = limit + 1;modifies found. Now whenwhilebegins the starting position has changed after the last coincidence.found, you are searching from the beginning of the string again, not from where you left off last time.blkhtml.find(urldown)doesn't depend on the current value offound- it gives you the same position every time through the loop, so you are just running in circles.