Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何添加常量以获取<&燃气轮机;(t) 元组在C+中的作用+;11? 我正在读《C++入门书》中的元组部分。 当我完成一个测试程序时,我遇到了一个问题。代码如下: #include <tuple> #include <iostream> using namespace std; tuple<int, bool, double> tuple1; int main() { tuple1 = make_tuple<int, bool, double>(1,true,3.3); for (int i = 0; i <tuple_size<decltype(tuple1)>::value; i++) { cout << get<i>(tuple1) << endl; } } #包括 #包括 使用名称空间std; 元组1; int main(){ tuple1=make_tuple(1,true,3.3); 对于(int i=0;i_C++_C++11_Tuples - Fatal编程技术网

如何添加常量以获取<&燃气轮机;(t) 元组在C+中的作用+;11? 我正在读《C++入门书》中的元组部分。 当我完成一个测试程序时,我遇到了一个问题。代码如下: #include <tuple> #include <iostream> using namespace std; tuple<int, bool, double> tuple1; int main() { tuple1 = make_tuple<int, bool, double>(1,true,3.3); for (int i = 0; i <tuple_size<decltype(tuple1)>::value; i++) { cout << get<i>(tuple1) << endl; } } #包括 #包括 使用名称空间std; 元组1; int main(){ tuple1=make_tuple(1,true,3.3); 对于(int i=0;i

如何添加常量以获取<&燃气轮机;(t) 元组在C+中的作用+;11? 我正在读《C++入门书》中的元组部分。 当我完成一个测试程序时,我遇到了一个问题。代码如下: #include <tuple> #include <iostream> using namespace std; tuple<int, bool, double> tuple1; int main() { tuple1 = make_tuple<int, bool, double>(1,true,3.3); for (int i = 0; i <tuple_size<decltype(tuple1)>::value; i++) { cout << get<i>(tuple1) << endl; } } #包括 #包括 使用名称空间std; 元组1; int main(){ tuple1=make_tuple(1,true,3.3); 对于(int i=0;i,c++,c++11,tuples,C++,C++11,Tuples,,您可以使用模板模拟for循环 #include <iostream> #include <tuple> template <size_t N> struct Printer { template <typename ... Args> static void print(std::tuple<Args ...> const& tuple) { Printer<N-1>::print(

,您可以使用模板模拟
for
循环

#include <iostream>
#include <tuple>

template <size_t N> struct Printer
{
   template <typename ... Args>
   static void print(std::tuple<Args ...> const& tuple)
   {
      Printer<N-1>::print(tuple);
      std::cout << std::get<N-1>(tuple) << std::endl;
   }
};

// Terminating specialization.
template <> struct Printer<0>
{
   template <typename ... Args>
   static void print(std::tuple<Args ...> const& tuple)
   {
      // Nothing to be done here.
   }
};

template <typename ... Args>
void printTuple(std::tuple<Args ...> const& tuple)
{
   Printer<std::tuple_size<std::tuple<Args ...>>::value>::print(tuple);
}

int main()
{
   std::tuple<int, bool, double> tuple1;
   tuple1 = std::make_tuple<int, bool, double>(1,true,3.3);

   printTuple(tuple1);
}

这一点类似:简短的答案为什么在C++中不容易做到这一点:简单地说,C++没有(你可以说它有一些有限的内省)。非常感谢。我是模板新手,我认为它很棒。“毛,我很高兴我能帮助你。