Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code is not working on my updated visual studio C++: #include using namespace std; int main() { string filename = Data3.txt; string line; ifstream

This code is not working on my updated visual studio C++:

#include using namespace std; int main() { string filename = "Data3.txt"; string line; ifstream myfile (filename.c_str()); ofstream myoutfile ("Volume.txt"); if (myfile.is_open()) { vector< int > tokens; while ( getline (myfile,line) ) { string buf; // Have a buffer string stringstream ss(line); // Insert the string into a stream // Create vector to hold our words while (ss >> buf) { tokens.push_back(atoi(buf.c_str())); } } myfile.close(); myoutfile << "Number" << "\t\t\t" << "volume" << "\t\t\t" << "radius" << "\t\t" << "Property" << endl; for (int i = 1; i < tokens.size(); ++i) { float r = float(tokens[i])/100.0; float volume = (4.0/3.0)*3.14*r*r*r; if(volume > 1.25 ) { myoutfile << i<< setprecision(2) << "\t\t\t" << volume<< "\t\t\t" << r << "\t\t" << "Large" << endl; } else { myoutfile << i << setprecision(2)<< "\t\t\t" << volume << "\t\t\t"<< r << "\t\t" << "Small" << endl; } } myoutfile.close(); } else { cout << "Unable to open file" << endl; exit(1); }

return 0; }

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

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions