next up previous contents index
Nächste Seite: 9.3 Umschalten der Ein-/Ausgabe Aufwärts: 9. File Input und Vorherige Seite: 9.1 Kopieren von Files   Inhalt   Index


9.2 Dateneingabe und -ausgabe via File

Die Dateneingabe und -ausgabe via File und Terminal kann gemischt benutzt werden. (siehe FileIO_a.cc)

//              FileIO_a.cc
#include <iostream.h>
#include <fstream.h>       // needed for ifstream and ofstream

int main()
{
 int n_t, n_f;
//			input file
 ifstream infile("in.txt");

 cout << "Input from terminal: ";
 cin  >> n_t;
 
 cout << "Input from file " << endl;
 infile >> n_f; 
//                      check it
 cout << endl;
 cout << "Input  from terminal was " << n_t << endl;
 cout << "Output from     file was " << n_f << endl;
 cout << endl;
//                      output file
 ofstream outfile("out.txt");

 cout << "This is an output to the terminal" << endl;
 
 outfile << "This is an output to the file" << endl; 
 
 return 0;
}


Gundolf Haase 2004-01-15