Skip to content

Instantly share code, notes, and snippets.

@kazmura11
Created October 4, 2014 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazmura11/fc6b429e951bdd6a3341 to your computer and use it in GitHub Desktop.
Save kazmura11/fc6b429e951bdd6a3341 to your computer and use it in GitHub Desktop.
STL map
#include <iostream>
#include <string>
#include <list>
#include <map>
#include <sstream>
using namespace std;
struct BWH {
string birthOfDate;
int bust;
int waist;
int hip;
};
// 使えないものは自作しちゃえ!
namespace patch
{
template <typename T> string to_string(const T& n)
{
ostringstream stm;
stm << n;
return stm.str();
}
}
static void oreNoYome(map<string, BWH>& idol)
{
string kekkonAite = "北川景子";
map<string, BWH>::iterator it = idol.find(kekkonAite);
// C++11限定 to_string()を使ってみる-> あれ?g++ 4.7.2未対応
string sb = (it->second.bust == 0 ? "不明" : patch::to_string(it->second.bust ));
string sw = (it->second.waist == 0 ? "不明" : patch::to_string(it->second.waist));
string sh = (it->second.hip == 0 ? "不明" : patch::to_string(it->second.hip ));
cout << ">>> 俺の嫁(" << it->first << ")のスリーサイズ <<<"
<< "\n生年月日 : " << it->second.birthOfDate
<< "\nB : " << sb
<< "\nW : " << sw
<< "\nH : " << sh << "\n";
}
int main()
{
map<string, BWH> idol;
idol.insert(pair<string, BWH>("石坂ちなみ", {"1984/06/23", 83, 58, 84}));
idol.insert(pair<string, BWH>("吉木りさ", {"1987/07/27", 80, 59, 88}));
idol.insert(pair<string, BWH>("倉持由香", {"1984/06/23", 84, 58, 100}));
idol.insert(pair<string, BWH>("北川景子", {"1986/08/22", 0, 0, 0}));
// 倫理的にエラー
//idol.insert(pair<string, BWH>("北川景子", "MyMxxtStick"); // まずいので伏字
for (auto i = idol.begin(); i != idol.end(); ++i)
{
int b = i->second.bust;
int w = i->second.waist;
int h = i->second.hip;
cout << i->first
<< "\n生年月日 : " << i->second.birthOfDate
<< "\nB : " << (b == 0 ? "不明" : patch::to_string(b))
<< "\nW : " << (w == 0 ? "不明" : patch::to_string(w))
<< "\nH : " << (h == 0 ? "不明" : patch::to_string(h)) << "\n";
}
oreNoYome(idol);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment