加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 05:42:58 所属栏目:百科 来源:网络整理
导读:如何通过C 11端子管线输入什么? 我可以像这样调用我的程序: 1. ./main solved.txt2. cat unsolved.txt | ./main3. cat unsolved.txt | ./main solved.txt 我正在使用它来知道是否需要从C行POSIX标准中读取管道中的数据: #include iostream#include sstrea
如何通过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
> 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.你忽略了将其包含在你的程序中.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读