结构体可直接赋值

    xiaoxiao2021-03-25  132

    #include "iostream" #include "vector" #include "algorithm" using namespace std; struct C { int a; vector<int> v; // 从小到大排 bool operator < (const struct C &c) const { return v < c.v; } }; int main() { C c; for(int i=0; i<3; i++) c.v.push_back(i); c.a = 10; C d; d = c; for(int j=0; j<3; j++) cout << d.v[j] << " "; cout << endl << d.a << endl << endl; C e; e.v.push_back(2); e.a = 11; e = c; for(j=0; j<3; j++) cout << d.v[j] << " "; cout << endl << d.a << endl; return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-11684.html

    最新回复(0)