So, I'm trying to read the portion between the 400 and the ***** in the following text file:
400
http://csweb.cs.wfu.edu
http://college.wfu.edu/cs/wp-content/themes/wfcollegeonepro
http://college.wfu.edu/cs/sample-page/feed
http://college.wfu.edu/cs/wp-includes/wlwmanifest.xml
http://college.wfu.edu/cs
http://www
http://www.wfu.edu
http://college.wfu.edu
http://college.wfu.edu/cs/news
*****
16331
http://college.wfu.edu/cs/wp-content/themes/wfcollegeonepro http://csweb.cs.wfu.edu
http://college.wfu.edu/cs/sample-page/feed http://csweb.cs.wfu.edu
http://college.wfu.edu/cs/wp-includes/wlwmanifest.xml http://csweb.cs.wfu.edu
http://college.wfu.edu/cs http://csweb.cs.wfu.edu
http://www http://csweb.cs.wfu.edu
http://www.wfu.edu http://csweb.cs.wfu.edu
I wrote the following code which (I'm pretty sure) accomplishes the task:
file2.open("./cswebDataCopy2.txt");
cout << "Opening cswebData.txt file..." << endl;
if(!file2)
{
cout << "System failed to open cswebData.txt..." << endl;
}
else
{
cout << "cswebData.txt successfully opened!" << endl;
}
cout << "READING FROM: cswebData.txt" << endl;
while(!file2.eof())
{
getline(file2,line4);
//cout << line4 << endl;
if(line4=="400")
{
cout << "Number of vertices in cswebData.txt: " << line4 << endl;
continue;
}
else if(line3=="*****")
{
cout << "Found the ****** " << endl;
break;
}
else
{
cout << "Couldn't find the 400 or ***** " << endl;
}
}
cout << "Code after while loop" << endl;
file2.close();
However, when I run the code, it only prints the code inside the else statement as many times as there are lines in the file and then the code after the while loop, even though the lines 400 and ***** are clearly in the file. So, I thought I would just print out the lines that are being read, just in-case any are being skipped. As it turns out, the program is reading all the lines correctly. Then, I thought it might have something to do with how I'm comparing in my if and else-if statements. So, I went ahead and re-wrote the code using the string compare function like so:
while(!file2.eof())
{
getline(file2,line4);
//cout << line4 << endl;
if(line4.compare("400")==0)
{
cout << "Number of vertices in cswebData.txt: " << line4 << endl;
continue;
}
else if(line4.compare("*****")==0)
{
cout << "Found the ***** " << endl;
break;
}
else
{
cout << "Couldn't find 400 or the ***** " << endl;
}
}
cout << "Code after the while loop" << endl;
However, after running the second version of my code, I still get the same (wrong) result as in my first version of the code. At this point, I am a tad bit confused on why my code isn't working. If anyone has an brilliant insight, that would be great. Thanks!