title: How to generate and compile C++ code while the program is running?
body: <p>So basically what I need isn't a specific code (of course that would be great), but just an idea and methods on how to achieve my goal.</p>
  
  <p>1) I have to create a program in C++ , which generates a little example of C++ code, that is each time a bit different. (This causes no problems for me, I will use a template and randomize some variables in the code, which will make it unique every time.)</p>
  
  <p>2) I will display the generated code and the user will have to type in, what he thinks the code prints out.</p>
  
  <p><strong>And here is where the problems start</strong>:</p>
  
  <p>3) I have to take the generated code and compile it somehow to get a string with the text that the program would have printed out.</p>
  
  <p>4) And then compare the string with what the user has typed in.</p>
  
  <p>So the step 3) is where I stop and can't figure it out without help... I was thinking to write the generated code in a function of a .cpp file and then call that function, but I couldn't get it to work, so I started to think, I should ask an expert, maybe there are some other methods or ideas how to achieve this.</p>