//inoutfiles.cpp //experiment with stream io, //including standard io //and from and to files. #include//cout, cin, endl #include //handles input & output files //ifstream, ofstream using namespace std; int main() { int n; char c, pagehold; float x; ifstream infile("myindata.txt"); //infile is my variable name for the input file //myindata.txt is a data file already set up. ofstream outfile("myoutdata.txt"); //outfile is my variable name for the output file //myoutdata.txt is a data file //by default it overwrites an existing file //can be set to append: // ofstream outfile("myoutdata.txt",ios::app); outfile << "This is the file myoutdata.txt\n"; cout << "This is the monitor screen.\n"; infile >> n >> c >> x; //infile works like cin //but you don't need the enter key cout << n << '\n' << c << '\n' << x << endl; //cout is still around to write on the screen //write these to the disk outfile << n << ' ' << n << c << x << c << endl; //write the same thing to the screen cout << n << ' ' << n << c << x << c << endl; cin >> pagehold; //cin still reads from the keyboard cin.ignore(80,'\n'); //mixing input from the keyboard and files //can lead to problems //Always use cin.ignore after input from cin. //You should also use, for example, infile.ignore(80,'\n') //when you know the next data in infile is on a new line. return 1; }