Hello all. I am trying to place sections of code into a string and I would eventually like to cout the string and then place in a compiler, so I need all the characters to stay in place and I would like to keep it the same as it was written so it can be read later. I can not figure out how to break the lines correctly and read the whole string. If someone can help me . Thanks
P.S. also I can not figure out how to place the comments in the string.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string txtbox;
txtbox = "#include \"engine.h\" \n
int main(int argc, char** argv) { \n
TWorld world; \n
TCamera cam; \n
Initialize(); \n
//Create a graphics context \n
Graphics(800,600); \n
//Create a world \n
world=CreateWorld(); \n
if (!world) { \n
MessageBoxA(0,\"Error\",\"Failed to create world.",0); \n
goto exitapp; \n
} \n
//Create render buffers \n
TBuffer gbuffer=CreateBuffer(800,600,BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL); \n
TBuffer lightbuffer=CreateBuffer(800,600,BUFFER_COLOR|BUFFER_DEPTH); \n
//Create a camera \n
cam=CreateCamera(); \n
CreateListener(cam);";
Instead of cout'ing the code, why don't you save it to a file. Then shell execute a compiler, passing the filename to it when you start it. Why do want to make a program this way though?
I am looking to make a simple gui to play around with. I would like to cin the code in sections and create just one string. Every time I cin I will += add to the string. At the end of the gui cout all of the code in one string all together.
Instead of getting code from the user, saving it to a file, then running a compiler, why don't you just make a small scripting language for whatever you need? Or just have a set of predefined commands?
I am just learning and if I could figure out how to break the lines in the string and allow the comments in the string it should be as simple as a hello world script. As I said I am only looking to do some low level stuff.
What am I doing wrong with the newline ?
Edit: also the cout of the string will not be used in the same compiler. just copy and paste when done.
Thanks for your replies. I guess I am not explaining my self very well. I am trying to have the output of the string look identical as the input. So then once done adding to the string I can cout, then select all and copy, then I can take all of the sections of code that I put together in the gui and paste it in a different compiler. That way when I paste in the other compiler I can read it like regular code.
If I do this it will cout the string across the screen. I want it to be like it was typed.
Thanks Disch Thats what I was looking for. I did not remember I could use quotation marks on your line three to keep the string going. Sorry for confusing everybody.
Thanks again Modshop.