8

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.

1

2 Answers 2

17

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++ -
Sign up to request clarification or add additional context in comments.

Comments

1

you can use here doc in the interactive shell. for example:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.