Question: What is the correct way for this code? I want to read the file but it can terminate the line when it reads '#' and

What is the correct way for this code? I want to read the file but it can terminate the line when it reads '#' and moves on to the next line. C++ only.

To put in a simplistic way:

#include #include #include #include

using namespace std;

int main() { string city1, city2; double amount; char stopEntry = '#'; ifstream open("graph2.txt");

if (open.fail()) cout << "Could not open the file.";

while (!open.eof()) { open >> city1; do { open >> city2; open >> amount; } while (!open >> stopEntry); }

cout << "Reading file completed" << endl;

return 0; }

Graphs2.txt

Atlanta Houston 650 Washington 600 # Austin Dallas 200 Houston 300 # Buffalo New_York 450 Newark 500 # Chicago Denver 550 New_York 950 # Dallas Austin 200 Chicago 1500 # Denver Atlanta 800 Chicago 550 # Houston Atlanta 650 # Newark # New_York Chicago 950 Buffalo 450 # Washington Atlanta 600 Dallas 700 #

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!