I want to read a file contents in C++ program which I have written inside a dll file. Right now I have hardcoded the path, but I want the path to be either dynamic or I should be able to use thru environment variable so I can either specify the path or the folder directly. I am using if stream in C++.Is there any way to do it
What I tried
if(const char* env_p = std::getenv("userdata"))
std::cout << "Your PATH is: " << env_p <<'\n';
std::vector<std::string> v;
string line;
//ifstream Myfile("C:\\Program Files\\Folder1\\users.txt"); working as its has hardcoded path
ifstream Myfile("users.txt");--- not working
ifstream Myfile(%userdata%);--- not working
while(!Myfile.eof())
{
while(getline(Myfile,line))
v.push_back(line);
cout <<endl;
cout <<"User in the file"<<endl;
for(auto i:v)
cout << i<<endl<<endl;
Myfile.close();
}