I have declared the following enum :
enum periods {one, five, ten, fifteen, thirty};
and now I want to pass it as a commandline argument in my main function.
int main(int argc, char* argv[]) {
periods mp;
if (argc == 2) {
std::string min_prd(argv[2]);
mp=atoi(min_prd.c_str());
}
and the compiler complains:
error: invalid conversion from ‘int’ to ‘periods’
I did atoi() because I figured enum is an int – how do I fix my code?
You have to explicitly cast it: