windowsgccpipe

how to use stdin pipe as source input for gcc?


This is my try:

CMD file:

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

code (irrelevant here): int main() {}

error I get:

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

I thought that the -x option is for signalizing stdin input, gcc itself said me that.


Solution

  • The -x option specifies the input language, but it doesn't tell g++ to read from stdin. To do that, you can pass a single dash (-) as a file name.

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