and it has become a long time since my last post here i just want to share this small snippet ive just have done to display some enviroment variables.
You can modifie the project freely its nth special hope it gives you just an idea on how to use the getenv() function in c++
i wish you all a good night im sleep now.
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
// Declairing Variables
char * GetEnviroment[10];
//Associate Pointer Variable
GetEnviroment[0] = getenv("TMP");
GetEnviroment[1] = getenv("APPDATA");
GetEnviroment[2] = getenv("COMPUTERNAME");
GetEnviroment[3] = getenv("HOMEDRIVE");
GetEnviroment[4] = getenv("HOMEPATH");
GetEnviroment[5] = getenv("OS");
GetEnviroment[6] = getenv("PROCESSOR_ARCHITECTURE");
GetEnviroment[7] = getenv("ProgramFiles");
GetEnviroment[8] = getenv("USERNAME");
GetEnviroment[9] = getenv("USERPROFILE");
GetEnviroment[10] = getenv("windir");
//Header Title
cout << "Some of Current System Enviroment Variables" << "\n" << "********************************************" <<endl;
//Looping until we reach the last element of GetEnviroment
for(int i = 0;i<10;i++)
{
cout << GetEnviroment[i] << "\n" << "------------------------" << endl;
}
system("PAUSE >> NULL");
return EXIT_SUCCESS;
}


Sign In
Create Account



Back to top









