簡介: CSDN博客專家,專注Android/Linux系統(tǒng),分享多mic語音方案、音視頻、編解碼等技術(shù),與大家一起成長!
優(yōu)質(zhì)專欄:Audio工程師進階系列【原創(chuàng)干貨持續(xù)更新中……】??
人生格言: 人生從來沒有捷徑,只有行動才是治療恐懼和懶惰的唯一良藥.
1.前言
本篇目的:C++之std::pair<uint64_t, size_t>應(yīng)用實例
v1.0
#include <iostream>
#include <utility>
#include <cstdint>
typedef std::pair<uint64_t, size_t> MapperKey;
int main(){
MapperKey key(123456789, 10);
std::cout << "MapperKey: " << key.first << ", " << key.second << std::endl;
return 0;
}
總結(jié):使用typedef將std::pair<uint64_t, size_t>重命名為MapperKey。然后,聲明了一個MapperKey類型的變量key,并初始化它的值為(123456789, 10)。最后,輸出MapperKey的值。文章來源:http://www.zghlxwxcb.cn/news/detail-653617.html
v2.0
#include <iostream>
#include <utility>
#include <cstdint>
#include <vector>
typedef std::pair<uint64_t, size_t> MapperKey;
int main(){
std::vector<MapperKey> keys;
MapperKey key1(123456789, 10);
MapperKey key2(987654321, 20);
MapperKey key3(555555555, 15);
keys.push_back(key1);
keys.push_back(key2);
keys.push_back(key3);
std::cout << "Iterating through MapperKeys:" << std::endl;
for (const MapperKey& key : keys)
{
std::cout << "Key: " << key.first << ", " << key.second << std::endl;
}
return 0;
}
總結(jié):首先使用typedef創(chuàng)建了MapperKey別名,創(chuàng)建了一個vector容器keys,用來存儲MapperKey對象。創(chuàng)建了MapperKey對象key1、key2和key3,并使用push_back函數(shù)將它們添加到keys容器中。使用for循環(huán)遍歷keys容器中的MapperKey對象,文章來源地址http://www.zghlxwxcb.cn/news/detail-653617.html
到了這里,關(guān)于C++之std::pair<uint64_t, size_t>應(yīng)用實例(一百七十七)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!