I'm wondering if i can create a program that reads texts file. In the text file is c++ code ... could that be compiled in the running exe?

So basically you'll have somehting like this in this first file:

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
ifstream infile;
infile.open("newtext.txt")
if (infile.fail())
{
cerr << "error.........

....

}


return 0;
}

compile that it runs and reads this:

#include <iostream>

using namespace std;

int main()
{
x = 7;
cout << 7;

return 0;
}

so instead of displaying the contents of that file it would compile it and the resulting window would be 7 rather than displaying the contents of the file?

Cheers

In effect you're trying to build a compiler...

a compiler in an exe file?

An application that is an interpreter.

A C++ Interpreter, that should be a fun project! One way to genuinely learn C++.

A simple method: Calls a compiler to compile the source files and calls the generated exe file , redirect its stdin, stdout.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.