Here is the sample code: #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stddef.h> #include <ostream> #include <iostream> #include <fstream> using namespace std; int main(int argc, char *argv[]) { char *filename; fstream filein; setbuf(stdout,NULL); filename = argv[1]; filein.open(filename,fstream::in); if (filein == NULL) { printf("Error opening %s\n",filename); exit(2); } else { printf("File opened correctly %s\n",filename); } return 0; } Compile command: make Here is the compile output: g++32 -w -g -c test.cpp g++32 -w -g -o test test.o This is the command: ./test test.out Output: Error opening test.out Thanks, Cristian