Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Whats the C++ equivalent of reading from stdin or a file
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="James Kanze, post: 3086309"] The standard Unix convention allows for more than one filename. What I usually do is something like: int main( int argc, char** argv ) { Gabi::MultipleFileIStream source( argv + 1, argv + argc ) ; process( source, std::cout ) ; return EXIT_SUCCESS ; } (The MultipleFileIStream class is available at my site: kanze.james.neuf.fr. It's actually one of the rare classes there which hasn't undergone much modification since I put it there.) Otherwise, the standard Unix idiom is: int main( int argc, char** argv ) { if ( argc <= 1 ) { process( std::cin, std::cout ) ; } else { for ( int i = 1 ; i < argc ; ++ i ) { std::ifstream source( argv[ i ] ) ; if ( ! source ) { std::cerr << argv[ 0 ] << ": cannot open " << argv[ i ] << std::endl ; } else { process( source, std::cout ) ; } } } return EXIT_SUCCESS ; } (There's also a singleton class, ProgramStatus, at my site which can be used to manage the exit status. MultipleFileIStream is in the IO subsystem, ProgramStatus in the Process subsystem.) [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Whats the C++ equivalent of reading from stdin or a file
Top