我可以像这样调用我的程序:
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
> Why does in_avail() output zero even if the stream has some char?
> Error “‘fdopen’ was not declared” found with g++ 4 that compiled with g++3
> stdio.h not standard in C++?
> error: ‘fileno’ was not declared in this scope
> GoogleTest 1.6 with Cygwin 1.7 compile error: ‘fileno’ was not declared in this scope
问题是当使用-std = C 11编译时,在stdio.h / cstdlib上,fileno和isatty是未定义的,因为它们是POSIX的东西.所以,一个解决方案是使用-std = GNU 11而不是-std = C 11.但是可以使用-std = C 11编写别的东西来编译吗?
解决方法
原文地址:https://www.jb51.cc/c/113945.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。