Why does reading a record struct fields from std::istream fail, and how can I fix it?

后端 未结 9 2121
野性不改
野性不改 2020-11-21 11:40

Suppose we have the following situation:

  • A record struct is declared as follows

struct Person {
    unsigned int id;
    std::st         


        
9条回答
  •  北恋
    北恋 (楼主)
    2020-11-21 12:13

    You have whitespace between firstname and lastname. Change your class to have firstname and lastname as separate strings and it should work. The other thing you can do is to read in two separate variables such as name1 and name2 and assign it as

    actRecord.name = name1 + " " + name2;
    

提交回复
热议问题