problem with setting environment variable

shell script: #!/bin/csh set VAR=12345 echo $VAR

will peacefully give the output 12345 at shell. I need to use C++ to do the same in some part of the code:

string str = "12345";
retValue="set var1= "+str;
system(retValue1.c_str());
system("echo $var1");

This doesn't create a system variable var1 and echos null which is understandable as each system function would create a child process with different environment variables. So I combine them as follows using just one system function...but it echos null again.

retValue="set var1= "+str;
retValue1=retValue+";\n echo $var1";
system(retValue1.c_str());

Can someone please guide me to set up the system variable thru C++. Thanks a lot in advance!

In C I would use man setenv ("linux"), there should be a C++ equivalent.