如何通过C 11端子管线输入什么?

如何通过C 11端子管线输入什么?,第1张

概述如何通过C 11端子管线输入什么? 我可以像这样调用我的程序: 1. ./main solved.txt2. cat unsolved.txt | ./main3. cat unsolved.txt | ./main solved.txt 我正在使用它来知道是否需要从C行POSIX标准中读取管道中的数据: #include <iostream>#include <sstream>#incl 如何通过C 11端子管线输入什么?

我可以像这样调用我的程序:

1. ./main solved.txt2. cat unsolved.txt | ./main3. 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编写别的东西来编译吗?

解决方法

C++ POSIX Standard

据我所知,没有这样的事情.有一个C POSIX库,它是POSIX标准的一部分.

So there is an alternative to them on the C++ 11?

标准C中没有其他选择(不在C11之前,到目前为止还没有).

您将需要依靠POSIX来获取所需的功能.

即使在POSIX中,它是unistd.h,它定义了isatty.你忽略了将其包含在你的程序中.

总结

以上是内存溢出为你收集整理的如何通过C 11端子管线输入什么?全部内容,希望文章能够帮你解决如何通过C 11端子管线输入什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1249391.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存