Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions