Is C++ cin a file descriptor and is possible to duplicate using dup()? I want to duplicate the standard input in order to use one for filestream using redirection from the shell and 开发者_Python百科one is for regular input after getting all the input from the file.
std::cin is bound to standard input file descriptor, in POSIX world it is defined as STDIN_FILENO and its value is usually 0. std::cin is just a special std::istream to read from that descriptor. You can use dup to duplicate it - no problem, you don't have to use std::cin for this purpose at all.
No.
std::cin is an input stream. This is a C++ concept that may under the scenes be implemented using (in part) a file handle. However, all you have access to is the stream object and its members.
You don't need to duplicate the stream, just create an fstream and read the data need.
加载中,请稍侯......
精彩评论