I have a question about using ifstream.
From text book, it tells me we can use like following
(2)Code:ifstream infile; infile.open("abc.txt"); if(!infile) cerr << "Error: uanable to open input file" << endl;
However, I just codes from some others using ifstreams*..
and I modify (1) to
Both pass compiling process, but somehow if abc.txt doesn't exist, thenCode:ifstream* infile; infile->open("abc.txt"); if(!(*infile)) cerr << "Error: uanable to open input file" << endl;
(1) shows the correct cerr message
(2) shows "Segmenation fault"
Actually I don't quite get the meaning of fstream
Isn't (2) same as (1)?
Can I think of ifstream like a file pointer? Then it reads EOF or other error which returns false value in if(infile).. And ifstream* is a pointer pointer to a file pointer?