I'm writing a Ruby code which generates a string containing a C++ program. For instance the Ruby string may contain:
#include <iostream>
using namespace std;int main(){cout<<"Hello World"<<endl;return 0;}
In order to run the C++ program stored in the Ruby string, I write the string into a file named c_prog.cpp, then use:
%x( g++ c_prog.cpp -o output )
to compile the C++ program in the file, then use:
value = %x( ./output )
and then print the value.
Since the C++ program stored in the Ruby string is very long (thousands of LOC), writing it to the file wastes some time. Is there any way I can compile the program stored in the string without writing it into a file? I mean something like:
%x( g++ 'the ruby string' -o output )
instead of:
%x( g++ c_prog.cpp -o output )