Generation

translateTue, 17 Jan 2023

#include <iostream> #include <fstream> #include <string> int main (){ std::ifstream myfile; myfile.open("shopping_list.txt"); std::string myline; if ( myfile.is_open() ) { while ( myfile ) { // equivalent to myfile.good() std::getline (myfile, myline); std::cout << myline << '\n'; } } else { std::cout << "Couldn't open file\n"; } return 0; }

#include <iostream> #include <fstream> #include <string> int main (){ std::ifstream myfile; myfile.open("shopping_list.txt"); std::string myline; if ( myfile.is_open() ) { while ( myfile ) { // equivalent to myfile.good() std::getline (myfile, myline); std::cout << myline << '\n'; } } else { std::cout << "Couldn't open file\n"; } return 0; }

Questions about programming?Chat with your personal AI assistant