//iostream.cpp
#include <stdio.h>
#include <iostream.h>
#include <strstream.h>
#include <fstream.h>

main()	{
   cout.sync_with_stdio();
		//output to standard output
   printf("Hello World\n");
   cout << "Hello World\n";
		//get input from standard input
   char name1[40];
   printf("Enter Name:");
   scanf("%s",name1);
   printf("%s was entered\n",name1);

   char name2[40];
   cout << "Enter Name Again:";
   cin >> name2;
   cout << name2 << " was entered" << endl;
		//output to and read from a memory buffer
   char buffer1[40];
   sprintf(buffer1,"%s","Hello World, printf(buffer)\n");
   printf("%s",buffer1);

   char buffer2[40];
   strstream stream(buffer2,sizeof(buffer2),ios::out);
   stream << "Hello world, strstream\n" << ends;
   cout << stream.str();
		//output to and read from a file
   FILE *file1 = fopen("file1.txt","w+");
   fprintf(file1,"Hello World, fprintf(file)\n");
   char data1[40];
   fseek(file1,0L,SEEK_SET); fgets(data1,sizeof(data1),file1);
   printf("%s",data1);

   fstream file2("file2.txt",ios::in | ios::out);
   file2 << "Hello World, fstream" << endl;
   char data2[40];
   file2.seekp(0L); file2.getline(data2,sizeof(data2));
   cout << data2;
		//redirect standard output to a file
   cout = *new ofstream("file.txt");
   cout << "Hello World, cout(ofstream)\n" << flush;
   ifstream ifFile("file.txt");
   ifFile.getline(data2,sizeof(data2));
   cerr << endl << data2 << endl;
}
/****************** output *********************
Hello World
Hello World
Enter Name:jim
jim was entered
Enter Name Again:jim
jim was entered
Hello World, printf(buffer)
Hello world, strstream
Hello World, fprintf(file)
Hello World, fstream
****************** output *********************/
//end iostream.cpp

