如何编写一个函数,无论数组是什么类型都输出它
How to write a function that print an array no matter what type it is?
我需要知道如何编写一个函数来打印数组,无论它是什么类型。比如如果我给一个整数数组或者字符串或者其他什么它就会打印出来
我是c++的新手,所以如果可能的话,你能不使用模板和STL吗?
给定数组/容器X
,您可以这样写:
template <class X>
void print_all(X &x)
{
for (auto y : x)
std::cout << y << std::endl;
}
相关文章:
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- 有人可以解释一下吗?这是关于数组和数组内部 if 语句的一些处理
- 如何从字符数组(不是字符串数组)中删除符号
- 如果我使用malloc()而不是堆栈数组,OpenGL不会渲染对象
- 如何判断指针是否是指向数组的指针
- 为什么这段代码给出错误......'a'是指针到字符指针,应该存储's'的地址,因为s是指向数组的第一个元素的指针
- 从C 到C#调用INT []显示随机大数字,而不是原始数组成员
- 将内存分配给 2D 数组时,“new int*[rowCount];”的含义是什么?是 2D 数组,是指向数组的指针数组
- 当我们使用字符串而不是字符数组时如何处理字符串的字符
- 如何将 c 字符串转换为指针数组,其中每个指针都是 char 数组中的一个单词
- 使用字符串而不是字符数组时程序崩溃
- 当参数之一是指针数组时,如何从C#调用C DLL
- 在C 中可能是字符串数组
- 这是缩小数组的有效方法吗?
- 这是什么数组声明
- C++-什么是指针数组版本的temp.pushback(temp[i])
- 为什么插入时动态分配的数组大小是初始数组的 2*大小,而不是大小+1?
- 不了解什么是内部数组
- 为什么我的程序是,数组中任意两个元素之间的最小差异,给出相反的结果
- 什么是连续数组