next up previous
Next: Pointers Up: C Primer CS 1005 Previous: Functions

Input/Output

Simple I/O:

  char no[7] = "number";
  cout << 3 << " is a " << no;

  int  i;
  char ch;
  char str[20];

  cin >> i >> ch >> str;
File I/O:

  #include <iostream.h>
  #include <fstream.h>
       
  char (database[80])[30];
  
  ifstream infile;
  infile.open("input.txt");
  int i = 0 ;
  while (infile.peek() != EOF) {
      infile >> database[i];
      i++;
  }
  infile.close();  

  ofstream outfile;
  outfile.open("outfile.txt");
  int size = i; // copy variable i from above into something meaningful
  for (i = 0; i < size; i++)
    outfile << database[i] << endl;
  outfile.close();


Andreas Koeller
2000-06-04