Source of syscalls.cpp


  1: // Filenme: SYSCALLS.CPP
  2: // Purpose: Illustrates how to make "system calls" from a C++ program.

  4: #include <iostream>
  5: #include <fstream>
  6: #include <cstdlib>
  7: using namespace std;

  9: #include "PAUSE.H"


 12: int main()
 13: {
 14:     cout << endl;
 15:     cout << "This program makes some \"system calls\".\n";
 16:     cout << "That is, it issues several commands to the operating system.\n";
 17:     cout << "Once again you should study the code and the ouput together.\n";
 18:     Pause(0);

 20:     // The program makes a "system call" to see if there are
 21:     // any files in the current directory with a .tmp extension:
 22:     system("dir *.tmp");
 23:     Pause(0);  cout << endl;

 25:     // It then creates a file called "ttt.tmp" and writes out
 26:     // to that file the first three positive integers:
 27:     ofstream outFile("ttt.tmp");
 28:     outFile << 1 << endl << 2 << endl << 3 << endl;
 29:     outFile.close();

 31:     // Then it checks again for files with a .tmp extension:
 32:     system("dir *.tmp");
 33:     Pause(0);  cout << endl;

 35:     // Finally it makes another "system call" to display the file:
 36:     system("type ttt.tmp");
 37:     Pause(0);  cout << endl;

 39:     return 0;
 40: }