C++ 標準模板庫 (STL) 中的 Pair


在本教程中,我們將討論一個程式來理解 C++ 標準模板庫中的 pair。

Pair 是 utility 標頭中定義的一個容器,它包含兩個值。它用於組合兩個值並關聯它們,即使它們是不同型別的。

示例

 即時演示

#include <iostream>
#include <utility>
using namespace std;
int main(){
   //initializing a pair
   pair <int, char> PAIR1 ;
   PAIR1.first = 100;
   PAIR1.second = 'G' ;
   cout << PAIR1.first << " " ;
   cout << PAIR1.second << endl ;
   return 0;
}

輸出

100 G

更新於: 14-Apr-2020

345 次瀏覽

啟動你的 職業生涯

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.