pair和make_pair用法
2015-12-18 16:59
627 查看
[cpp] view
plaincopyprint?
// pair简单讲就是将两个数据整合成一个数据
// 本质上是有first, second两个成员变量的结构体
extern void test_pair()
{
// pair两种构造的方法
// 方法1
std::pair<std::string, double>("This is a StringTest0.", 9.7); // 浮点数默认是double, float的话有会警告。
std::pair<std::string, double> pA("This is a StringTest.", 9.7);
// 方法2
std::pair<std::string, double> pB;
pB = std::make_pair("This is a StringTest.", 9.9);
// pair的输出
std::cout << pA.first << std::endl;
std::cout << pA.second << std::endl;
// 结合map的使用
std::map<std::string, double> mA;
mA.insert(pA);
mA.insert(pB);
for (std::map<std::string, double>::iterator it = mA.begin(); it != mA.end(); ++it)
{
std::cout << "First Member: " << it->first << std::endl;
std::cout << "Second Member: " << it->second << std::endl;
}
}
plaincopyprint?
// pair简单讲就是将两个数据整合成一个数据
// 本质上是有first, second两个成员变量的结构体
extern void test_pair()
{
// pair两种构造的方法
// 方法1
std::pair<std::string, double>("This is a StringTest0.", 9.7); // 浮点数默认是double, float的话有会警告。
std::pair<std::string, double> pA("This is a StringTest.", 9.7);
// 方法2
std::pair<std::string, double> pB;
pB = std::make_pair("This is a StringTest.", 9.9);
// pair的输出
std::cout << pA.first << std::endl;
std::cout << pA.second << std::endl;
// 结合map的使用
std::map<std::string, double> mA;
mA.insert(pA);
mA.insert(pB);
for (std::map<std::string, double>::iterator it = mA.begin(); it != mA.end(); ++it)
{
std::cout << "First Member: " << it->first << std::endl;
std::cout << "Second Member: " << it->second << std::endl;
}
}
相关文章推荐
- [转]strong,weak, retain, assign的区别
- macbook air 只安装win7系统
- 详解Paint的setShader(Shader shader)
- 如何解决SVN Commit failed (details follow): Access denied
- LeetCode 172:Factorial Trailing Zeroes
- Exmail 邮件系统维护备忘录
- 通过aidl实现挂断电话
- HDU 1789Doing Homework again 贪心
- iptables:应用防火墙规则:iptables-restore: line 18failed
- ORA-27603: Cell storage I/O error, I/O failed on disk ORA-27626: Exadata error:
- [BetterExplained]如何有效地记忆与学习
- [BetterExplained]为什么你应该(从现在开始就)写博客
- 我遇到的错误:“Linker command failed with exit code 1” 的解决方案
- openerp 不能发送email,请配置发件人的email地址或者别名
- MongoDB 3.0的Explain
- AEAI EM费用管理系统V1.0.2版本开源发布
- AEAI EM费用管理系统V1.0.2版本开源发布
- 画布
- quartus II 15.0 中解决仿真报错 Error: (vsim-19) Failed to access library 的问题
- 文件内容查看 cat tac head tail more less