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

📄 chap1_stlmapexample.cpp

📁 游戏开发特殊技巧-special.effects.game.programming
💻 CPP
字号:
#pragma warning(disable: 4786)

#include <conio.h>
#include <map>
#include <string>
#include <iostream>

using namespace std;

class CBook
{
public:
  CBook() { }

  CBook(string strAuthor, string strTitle, string strISBNNumber) {
    m_strAuthor = strAuthor; m_strTitle = strTitle; m_strISBNNumber = strISBNNumber;
  }

  string m_strAuthor;
  string m_strTitle;
  string m_strISBNNumber;
  /* other info - etc */
};

void main(void)
{
  map<string, CBook> books;
  
  // add a couple of books to our database.
  CBook SpecialEffectsBook("Mason McCuskey", 
    "Special Effects Game Programming With DirectX", "0-7615-3497-0");
  CBook IsoBook("Ernest Pazera", 
    "Isometric Game Programming With DirectX", "0-7615-3089-4");
  CBook OpenGLBook("Kevin Hawkins and Dave Astle", 
    "OpenGL Game Programming", "0-7615-3330-3");

  // insert these books into our map
  books.insert(make_pair(SpecialEffectsBook.m_strISBNNumber, SpecialEffectsBook));
  books.insert(make_pair(IsoBook.m_strISBNNumber, IsoBook));
  books.insert(make_pair(OpenGLBook.m_strISBNNumber, OpenGLBook));

  // allow the user to search for one
  string strISBN;

  cout << "Enter an ISBN number and, if it's in my little database, I will tell you what book it's for:" << endl;
  cin >> strISBN;

  map<string, CBook>::iterator it;
  it = books.find(strISBN);
  if (it == books.end()) { // not found!
    cout << "I don't know about that book.";
  }
  else {
    CBook &theBook = it->second;

    cout << "Here's what I know about that book:" << endl << endl;
    cout << "Title: " << theBook.m_strTitle << endl;
    cout << "Author: " << theBook.m_strAuthor << endl;
    cout << "ISBN: " << theBook.m_strISBNNumber << endl;
    cout << endl << endl;
  }

#ifdef _DEBUG
  getch();
#endif
}

⌨️ 快捷键说明

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