vector <struct> 使用

#include <iostream>
#include <vector>
using namespace std;

struct NODE
{
 int m_nRoleID;
 int m_nScore;
 string m_strROleName;
 NODE() :
  m_nRoleID(1), m_nScore(0),m_strROleName("byfei")
 {
 }
 NODE(const int nRoleID, const int nScore,const string strRoleName) :
  m_nRoleID(nRoleID), m_nScore(nScore),m_strROleName(strRoleName)
 {
 }
};

vector<NODE> v;

int main()
{
 for (uint i = 0; i < 10; i++)
  v.push_back(NODE());
 for (uint i = 0; i < v.size(); i++)
 {
  v[i].m_nRoleID = 2;
  v[i].m_nScore = 1;
  v[i].m_strROleName = "byf";
  cout << v[i].m_nRoleID << " " << v[i].m_nScore <<" "<< v[i].m_strROleName << endl;
 }
 getchar();
 return 0;
}

原文地址:https://www.cnblogs.com/byfei/p/3112330.html