如何通过C 11端子管线输入什么?
如何通过C 11端子管线输入什么?
我可以像这样调用我的程序: 1. ./main solved.txt 2. cat unsolved.txt | ./main 3. cat unsolved.txt | ./main solved.txt 我正在使用它来知道是否需要从C行POSIX标准中读取管道中的数据: #include <iostream> #include <sstream> #include <stdio.h> #include <unistd.h> int main( int argumentsCount,char* argumentsStringList[] ) { std::stringstream inputedPipeLineString; if( argumentsCount > 1 ) { printf( "argumentsStringList[1]: %s",argumentsStringList[ 1 ] ); } // If it is passed input through the terminal pipe line,get it. if( !isatty( fileno( stdin ) ) ) { // Converts the std::fstream "std::cin" to std::stringstream which natively // supports conversion to string. inputedPipeLineString << std::cin.rdbuf(); printf( "inputedPipeLineString: %s",inputedPipeLineString.str().c_str() ); } } 但是现在我想使用C11标准,而我所爱的fileno和isatty也是这样的.那么在C 11上有一个替代方案呢? 相关主题: > checking data availability before calling std::getline 问题是当使用-std = C 11编译时,在stdio.h / cstdlib上,fileno和isatty是未定义的,因为它们是POSIX的东西.所以,一个解决方案是使用-std = GNU 11而不是-std = C 11.但是可以使用-std = C 11编写别的东西来编译吗? 解决方法
据我所知,没有这样的事情.有一个C POSIX库,它是POSIX标准的一部分.
标准C中没有其他选择(不在C11之前,到目前为止还没有). 您将需要依靠POSIX来获取所需的功能. 即使在POSIX中,它是unistd.h,它定义了isatty.你忽略了将其包含在你的程序中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |