⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex10_02.cpp

📁 This rar contains code from every chapter of Wrox.Ivor.Hortons.Beginning.Visual.C.Plus.Plus.2008.Mar
💻 CPP
字号:
// Ex10_02.cpp
// Storing objects in a vector

#include <iostream>
#include <vector>
// #include <algorithm>                // Uncomment to sort
#include "Person.h" 

using std::cin;
using std::cout;
using std::endl;
using std::vector;
// using std::sort;                    // Uncomment to sort

int main()
{
  vector<Person> people;               // Vector of Person objects
  const size_t maxlength = 50;
  char firstname[maxlength];
  char secondname[maxlength];
  while(true)
  {
    cout << "Enter a first name or press Enter to end: ";
    cin.getline(firstname, maxlength, '\n'); 
    if(strlen(firstname) == 0)
      break;
    cout << "Enter the second name: ";
    cin.getline(secondname, maxlength, '\n'); 
    people.push_back(Person(firstname, secondname));
  }

//  sort(people.begin(), people.end());     // Uncomment to sort

  // Output the contents of the vector
  cout << endl;
  vector<Person>::iterator iter = people.begin();  
  while(iter != people.end())
    iter++->showPerson();

  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -