【问题标题】:how to use stdin pipe as source input for gcc?如何使用标准输入管道作为 gcc 的源输入?
【发布时间】:2013-01-11 20:50:57
【问题描述】:

这是我的尝试:

CMD 文件:

@SET PATH=%PATH%;D:\mingw\bin
type test10.cpp | g++ -xc++ -o test10.exe

代码(此处无关):int main() {}

我得到的错误:

g++: fatal error: no input files
compilation terminated.

我认为 -x 选项是用于表示标准输入的信号,gcc 本身就是这么说的。

【问题讨论】:

标签: windows gcc pipe


【解决方案1】:

您可以在交互式 shell 中使用here doc。 例如:

gcc -x c - <<eof
#include <stdio.h>

void foo()
{
    int a = 10;
    static int sa = 10;

    a += 5;
    sa += 5;

    printf("a = %d, sa = %d\n", a, sa);
}


int main()
{
    int i;

    for (i = 0; i < 10; ++i)
        foo();
}
eof

reference

【讨论】:

    【解决方案2】:

    -x 选项指定输入语言,但它不告诉 g++ 从标准输入读取。为此,您可以传递一个破折号作为文件名。

    type test10.cpp | g++ -o test10.exe -x c++ -
    

    【讨论】:

      猜你喜欢
      • 2016-04-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-11
      • 1970-01-01
      • 2013-11-04
      • 2015-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多