簡體   English   中英

在C ++中使用元組作為元素訪問元組

[英]accessing tuple with tuple as elements in C++

如何使用get訪問以tuple為元素的元組?

vector<tuple<string, int, vector<tuple<string, int, string>>>> setOfWord

如果我使用元組以對作為元素,

vector <tuple<string, int, vector<pair<string, string>>>> setOfWord

我可以通過使用訪問元素

if( wordVector ==  (get<2>(setOfWord[i]))[j].second)

但是,如果我使用元組而不是對,如何檢索內部元素呢?

謝謝

這樣嘗試

#include <iostream>
#include <vector>
#include <string>
#include <tuple> // for swap() and tuple 

using namespace std; 

int main() {
  vector<tuple<string, int, vector<tuple<string, int, string>>>> setOfWord;
  tuple <string,int,string> tup1("20",1,"17.5"); 
  vector< tuple <string,int,string>> v;
  v.push_back(tup1);
  tuple<string, int, vector<tuple<string, int, string>>> vt("str", 2, v);
  setOfWord.push_back(vt);
  cout<<get<0>(get<2>(setOfWord[0])[0]);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM