P
Paulo da Silva
Hi,
Pls. consider the following code:
using namespace std;
#include <iostream>
#include <fstream>
int main(int argc,char **argv)
{ ifstream *in_p;
int val;
if (argc==2)
{ in_p=new ifstream(argv[1]);
// Test in_p->good()
}
else
in_p=static_cast<ifstream*>(&cin);
*in_p >> val;
cout << "val=" << val << endl;
if (in_p!=&cin)
delete in_p;
return 0;
}
In the line "in_p=static_cast<ifstream*>(&cin);" both static and
reinterpret casts seem to work. Which is (more) correct?
Thanks.
Pls. consider the following code:
using namespace std;
#include <iostream>
#include <fstream>
int main(int argc,char **argv)
{ ifstream *in_p;
int val;
if (argc==2)
{ in_p=new ifstream(argv[1]);
// Test in_p->good()
}
else
in_p=static_cast<ifstream*>(&cin);
*in_p >> val;
cout << "val=" << val << endl;
if (in_p!=&cin)
delete in_p;
return 0;
}
In the line "in_p=static_cast<ifstream*>(&cin);" both static and
reinterpret casts seem to work. Which is (more) correct?
Thanks.