Hey all!
I was thinking about how to make a program, in which you write some c++ code and program tests that code with given examples.

For example you input following code in that program:

#include <iostream>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a + b;
	return 0;
}

the program compiles and tests the code (for example it tests if you input 1 and 3, will 4 be written in console using that code) and gives you information if the program is working or not.

Or in other words, how to make program that compiles given code (using compiler, for example g++) and tests it.

Thanks! :)

Recommended Answers

All 2 Replies

g++ filename.cpp

will make a.out file.

to run a.out file type: ./a.out

file will run.

can make a pernimate file by typing:

g++ -o pernimatefile filenametocompile.cpp

>> will create a executable pernimatefile that wont be over writen everytime you
compile a different program.

Thanks. This is what I have now. test.cpp includes written code.

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
    system("g++ -o -Wall C:\\Users\\%USERNAME%\\Documents\\test.cpp");
    system("g++ ./test.o");
}

How can I test that program with examples? Sorry for beeing "noob" but this is completely new field for me, I've never done anything like this before.. :)

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.