I am trying to create a program to open a file using values in environment variables..
My code:
#include<iostream>
#include<cstdlib>
#include<sstream>
#include<cstring>
using namespace std;
void main(int argc, char *argv[])
{
std::stringstream stream;
int a;
cout<<"Press 1 to open Remainder: "<<endl;
cout<<"Press any other key to exit: "<<endl;
cin>>a;
if(a==1)
{
system("\"C:\\Documents and Settings\\%USERNAME%\\My Documents\\CorelDRAW X3.txt\"");
// system(stream.str().c_str());
}
else
{
exit(0);
}
}
This is the output:
Press 1 to open Remainder:
Press any other key to exit:
1
'C:\Documents' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .
But when i type my username then it runs perfectly..
I want to use this program in another computer so i used environment variables
Any help?
Thanks.