Sam Saint-Pettersen
Sam Saint-Pettersen

Reputation: 511

Pipe file contents in g++ to compile

Is it possible to pipe the contents of a file into g++ to compile a program?

I want to do this because I want to use a file from a database rather than a physical file on a disk. The file contents can be easily retrieved via an API I have made.

For instance, I would like to do something like:

g++ contents_of_file -o executable

Thanks a lot.

Sam.

Upvotes: 3

Views: 1845

Answers (3)

lekstam
lekstam

Reputation: 36

I commonly use this approach and I find the quickest and cleanest approach is:

g++ $(<args.txt)

Or in the questions exact framing:

g++ $(<file_containing_content) -o executable

Upvotes: 0

aminorex
aminorex

Reputation: 126

more fun:

alias true="gcc -xc++<(echo 'main()<%int(*)(int*)=6 "\?"<[:0:>;%>')&&a.out"

hey, works for me.

Upvotes: 0

Joachim Isaksson
Joachim Isaksson

Reputation: 181027

Yes, you can pipe to gcc if you specify the language using the -x option;

echo "int main(){}" | gcc -Wall -o testbinary -xc++ -

Upvotes: 4

Related Questions