system

Can you pass your code directly into gcc? For example: gcc -? 'int main(){return 0;}'

≡放荡痞女 提交于 2021-01-27 18:54:19
问题 Can you pass your code directly into gcc? If so what is the command line option for it? For example: g++ -? 'int main(){return 0;}' I need to know because I am using a system command and I rather not make files: system("g++ -C "+code_string+" -o run.out"); Basile Starynkevitch solution worked, however I am getting compile errors when I use newlines: echo '#include\nint main(){printf("Hello World"); return 0;}' | g++ -x c++ -Wall -o myprog /dev/stdin Edit: fixed it echo -e '#include\nint main(