R
Ralf Goertz
Hi,
consider the following program
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]){
if (argc<2) exit(1);
ifstream infile;
if (argv[1]!="-")
infile.open(argv[1]);
else
infile=cin; //doesn't compile
// read from infile
return 0;
}
In c I can just assign stdin to a FILE*. What would be the c++ way of
doing this? Do I have to use a pointer here, too? I could use
infile.open("/dev/stdin") but that's probably not portable.
Thanks,
Ralf
consider the following program
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[]){
if (argc<2) exit(1);
ifstream infile;
if (argv[1]!="-")
infile.open(argv[1]);
else
infile=cin; //doesn't compile
// read from infile
return 0;
}
In c I can just assign stdin to a FILE*. What would be the c++ way of
doing this? Do I have to use a pointer here, too? I could use
infile.open("/dev/stdin") but that's probably not portable.
Thanks,
Ralf