#include #include #include using namespace std; int main() { ofstream output; ifstream input; string info; int i; // open a file and write 3 things to it output.open("Example.txt"); output << "One\n"; output << "Two\n"; output << "Three\n"; output.close(); // close the output file // open a file and read from it input.open("Example.txt"); // input >> info; // cout << "First item: " << info << endl; // input >> info; // cout << "Second item: " << info << endl; cout << "\nWHILE LOOP \n" << "----------" << endl; while(input >> info) { cout << "while: " << info << endl; } input.close(); info = "Empty"; input.open("Example.txt"); cout << "\nDO LOOP \n"; do { cout << "Do: " << info << endl; } while(input >> info); input.close(); // close the input file info = "Nothing"; // use a for loop to write to the file output.open("garbage.txt"); for (i=0; i<10; i++) { output << i << endl; } output.close(); // close garbage // use a for loop to read to the file input.open("garbage.txt"); for (i=0; i<10; i++) { input >> i; cout << i << endl; } input.close(); // close garbage // i = 0; cout << "i = " << i << endl; switch(i) { case 10: cout << "Ten" << endl; while(false) // endless loop - won't run { cout << "Class is done...." << endl; } for (int a = 0; a<4; a++) { cout << "You got an A" << endl; } break; case 1: cout << "One" << endl; break; case 2: cout << "Two" << endl; break; default: cout << "None of the above" << endl; break; } return 0; }