#include #include #include #include #include #include using namespace std; class textfile { string text; vector links; int extractlinks(); void removecrlf(); public: printlinks(); textfile(string filename); ~textfile(); }; textfile::~textfile() { links.clear(); }; void textfile::removecrlf() { for (int i=0;i",pos); if (endoflink== string::npos) // hit the end? endoflink = text.size(); endoflink += 4; // // Extract url and add to the list pos = endoflink + 1; links.push_back( text.substr(startoflink, endoflink-startoflink) ); ++count; } while (true); return count; } textfile::textfile(string filename) { string temp; std::ifstream file; file.open(filename.c_str(), std::ios::in | std::ios::binary); if (file.is_open() ) { file.seekg(0, std::ios::end); std::streamsize length = file.tellg(); if (length != 0) { text.reserve( length ); file.seekg(0, std::ios::beg); while(getline(file, temp)) // Discards newline char text += temp; } } file.close(); removecrlf(); extractlinks(); sort( links.begin(),links.end()); } textfile::printlinks() { for (int i=0;i < links.size(); i++) { string url= links[i]; cout << "Link " << i+1 << ": " << url << endl; } } int main(int argc, char* argv[]) { textfile test("Your file name here"); test.printlinks(); return 0; }