Vector of Structures

前端 未结 6 430
悲哀的现实
悲哀的现实 2021-01-18 11:42

I have some code given to me by another person in which we have a structure

struct Pair {
    string s1;
    string s2;
    bool equivalent;
  };
         


        
6条回答
  •  抹茶落季
    2021-01-18 12:37

    Why is it failing?

    Because it’s not valid C++. It will be, in C++0x. But as of yet, it’s just not valid. And since your compiler doesn’t yet support C++0x, you will need to do it the hard way, i.e. populate the vector one element at a time, or copy from a C array …:

    Pair data[] ={ {"string","string2",true}, 
        {"string","string3",true}, 
        {"string","string4",false}, 
        {"string","string7",false}, 
        {"string3","string8",false} };
    PairID.assign(data, data + sizeof(data) / sizeof(Pair));
    

    (This will require the algorithm and iterator standard headers.)

提交回复
热议问题