1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
template <typename T>
void printArray(std::ostream& os, const T* a, size_t sz,
const char *delim=" ", const char *end="\n")
{
if (sz > 0) {
std::cout << a[0];
for (std::size_t i = 1; i < sz; i++)
std::cout << delim << a[i];
}
std::cout << end;
}
int main() {
using std::cout;
int a[] = {1, 2, 3, 4};
size_t sz = sizeof a / sizeof *a;
printArray(cout, a, sz);
printArray(cout, a, sz, " ", " :: ");
printArray(cout, a, sz, ", ");
printArray(cout, a, sz, "\n", "\n\n");
}
|