Reputation: 307
So lets say I had a string that was
<html>
<head><title>301 Moved Permanently</title><head>
and so
I'm using the str.find();
to find where the title tag starts and it gives me the correct position but how would I go about printing just the
301 Moved Permanently
My code:
string requestedPage = page.GetBody(); //Get the body of a page and store as string "requestedPage"
int subFromBeg = requestedPage.find("<title>"); //Search for the <title> tag
int subFromEnd = requestedPage.find("</title>"); //Search for the </title> tag
std::cout << requestedPage; //before
requestedPage.substr( subFromBeg, subFromEnd );
std::cout << requestedPage; //after
Upvotes: 0
Views: 134
Reputation: 168726
requestedPage.substr( subFromBeg, subFromEnd );
should be
requestedPage = requestedPage.substr( subFromBeg, subFromEnd );
std::string::substr
doesn't modify the string, it returns a modified copy of the string.
Upvotes: 1