Wrapping "int main(int argc, char** argv)"

What is the recommended method for wrapping “int main(int argc, char** argv)” ?

Thanks,
Oran

// test.C
#include
#include
#include
#include

using namespace std;

int main(int argc, char** argv) {

if (argc < 3)
return(EXIT_FAILURE);

ifstream in(argv[1]);
ofstream out(argv[2]);

if (!in || !out)
return(EXIT_FAILURE);

char c;
while (in.get©) {
if (c == ‘\t’)
out << " "; // 3 spaces
else
out << c;
}

out.close( );

if (out)
return(EXIT_SUCCESS);
else
return(EXIT_FAILURE);
}

void test(){

extern char *__progname;

vector<const char*> v;
v.push_back(__progname);

string s;
while (getline(cin, (s=new string()), ’ ')) {
v.push_back(s->c_str());
}
cout << main(v.size(), (char
)v.data()) << endl;
}

echo “file.in file.out” | cling -std=c++11 test.C

Hi,

main() might be problematic because cling already has one. Does it work after renaming main()? If not, what’s the error message you get?

Axel.

Hi Axel.

I don’t have an issue, cling is working as expected. The posted code works. I was just wondering if there is a recommended way of wrapping an existing c/c++ program such that the program could process argc and argv.

Thanks,
Oran