如何编写一个函数,无论数组是什么类型都输出它

How to write a function that print an array no matter what type it is?

本文关键字:是什么 数组 类型 输出 何编写 函数 一个      更新时间:2023-10-16

我需要知道如何编写一个函数来打印数组,无论它是什么类型。比如如果我给一个整数数组或者字符串或者其他什么它就会打印出来

我是c++的新手,所以如果可能的话,你能不使用模板和STL吗?

给定数组/容器X,您可以这样写:

template <class X>
void print_all(X &x)
{
    for (auto y : x)
        std::cout << y << std::endl;
}