Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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
C++ C++;尝试使用模板输出函数显示不同类型的数据_C++_Templates - Fatal编程技术网

C++ C++;尝试使用模板输出函数显示不同类型的数据

C++ C++;尝试使用模板输出函数显示不同类型的数据,c++,templates,C++,Templates,我创建了一个函数,该函数应该输出数据类型,包括int、char、string和一个名为item的类。这就是功能: template < typename T > void Output(const T* first, const T* last, char outforchar= '\0') { if (outforchar== '\0') { std::for_each(first, last, [](T i){std::cout << i;});

我创建了一个函数,该函数应该输出数据类型,包括int、char、string和一个名为item的类。这就是功能:

template < typename T >
void Output(const T* first, const T* last, char outforchar= '\0')
{
  if (outforchar== '\0')
  {
    std::for_each(first, last, [](T i){std::cout << i;});
  }
  else 
  {
    std::for_each(first, last, [outforchar](T i){std::cout << i << outforchar;});
  }
}
我似乎不明白如何在函数中实现这一点,我做错了什么?

首先

[](T const& i){std::cout << i;}

[](T const&i){std::cout,拜托。你做错了的是你没有提供一个,正如stackoverflow.com中所解释的。输出运算符是类文件中的问题。出于某种原因,它被注释掉了。哇!我真的很感谢你的时间。
for (auto i = first; i != last; ++i) 
{
  std::cout << i;
}
for (typename E::ConsItr i = e.Begin(); i != e.End(); ++i)
[](T const& i){std::cout << i;}
std::ostream& operator<<(std::ostream& os, const SomeType& x)