For example this works
#include <iostream>
#include <cstdlib>
int main()
{
if(const char* env_p = std::getenv("PATH"))
std::cout << "Your PATH is: " << env_p << '\n';
}
but this doesn't
#include <iostream>
#include <cstdlib>
int main()
{
if((const char* env_p = std::getenv("PATH")) && (const char* env_p = std::getenv("PATH")))
std::cout << "Your PATH is: " << env_p << '\n';
std::cout << "Your PATH is: " << env_p << '\n';
}
main.cpp: In function 'int main()':
main.cpp:6:9: error: expected primary-expression before 'const'
6 | if((const char* env_p = std::getenv("PATH")) && (const char* env_p = std::getenv("PATH")))
| ^~~~~
main.cpp:6:9: error: expected ')' before 'const'
6 | if((const char* env_p = std::getenv("PATH")) && (const char* env_p = std::getenv("PATH")))
| ~^~~~~
How do you check all env parameter exist?
I can do nested if, but that seems ugly