I need to write a program that reads from either ifstream or cin, depending on the parameters passed to the program at runtime.
I planned to do the following:
istream in; if(argv[1] == "cin") { in = cin; } else { ifStream inFile; inFile.open(argv[1].c_str()); in = inFile; }
However, istream is protected, and I cannot declare istream in. Is there a way to declare such a shared thread in a thread?
istream*. , , . , , . , "inFile" , . :
istream*
istream* in; ifStream inFile; if(!strcmp(argv[1],"cin")) { in = &cin; } else { inFile.open(argv[1]); in = &inFile; } // use *in
( . .)
cin, , . , , .
cin
,
program.exe cin
program.exe
program.exe myfile.txt
program.exe < myfile.txt
* nix Windows.
:
ifStream inFile; istream in( argv[1] == "cin" ? cin : inFile.open(argv[1]));
Source: https://habr.com/ru/post/1731806/More articles:Как я могу использовать SharpSVN в моем собственном проекте Mono (С#)? - c#Using a utility to generate Java code to make my project more concise. A good idea? - javaSQLite SQL Update Date - dateApache2 proxy error mod_proxy - apache2Is immutability and flex a bad mix? - immutabilityFailed to connect to MySQL MySQL - phpHow to get PC local IP address in Oracle ApEx - oracleHow to manage the screensaver name specified in the drop-down list? - c #Refactoring Fun - Prime Numbers - c #Создание UIView в построителе интерфейса, который автоматически центрируется при добавлении в качестве подвью - iphoneAll Articles