declaring generic istream in c++-Collection of common programming errors

Try with an istream* instead. Note, however, that you have to change your code slightly. Using pointers you have to preserve the memory area of the object that you’re pointing. In other words, the “inFile” variable cannot be declared there, as it won’t exist out of the else. The code could be, then:

 istream* in;
 ifStream inFile;

 if(!strcmp(argv[1],"cin"))
 {
      in = &cin;
 }
 else
 {
      inFile.open(argv[1]);
      in = &inFile;
 }
 // use *in

(Note also the modifications in the string handling. I modified them as an example.)