c++ Read from file get struct enum value -


enum person {person1name, person2name, person3name};  struct myinfo {   person person ; } 

let person type name "john", , infile >> (what should write here read user type name , associate enum person2name);

hard understand need, reading strings , converting them enum value can done explicit ifs

std::ifstream in(...); std::string name; in >> name; myinfo info; if (name == "john")    info.person = person2name; 

or maps

std::map<std::string, person> map; map["john"] = person2name; in >> name; info.person = map[name]; // ugly! not checking if name in map (use std::map::find in real code) 

still it's strange hardcode available names enum in code.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -