如何使用stdin管道作为gcc的源输入?

rsk*_*k82 7 windows gcc pipe

这是我的尝试:

CMD文件:

@SET PATH=%PATH%;D:\mingw\bin
type test10.cpp | g++ -xc++ -o test10.exe
Run Code Online (Sandbox Code Playgroud)

代码(这里不相关): int main() {}

错误我得到:

g++: fatal error: no input files
compilation terminated.
Run Code Online (Sandbox Code Playgroud)

我认为-x选项用于表示stdin输入,gcc本身就是这么说的.

Joh*_*ica 15

-x选项指定输入语言,但它不告诉g ++从stdin读取.为此,您可以将单个短划线作为文件名传递.

type test10.cpp | g++ -o test10.exe -x c++ -
Run Code Online (Sandbox Code Playgroud)