简体   繁体   中英

Default string value for empty field in struct

Say I have a structure called Names

struct Names {
   std::string first_name;
   std::string middle_name;
   std::string last_name;
}

Later I add first and last name to the structure, but nothing for the middle name. If I want to check at some point if middle name exists (from many structs like this) and do something to it, what do I compare it to? Is it false or empty string such as `middle_name = "";?

The default constructor builds an empty string with a length of 0 characters. https://www.cplusplus.com/reference/string/string/string/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM