I am trying to code a function that takes in a range of values and prints them using std::cout. This is the prototype
1 2
template < typename T >
void Output(const T* first, const T* last, char outForChar= '\0')
This function is supposed to output the data in the range [first, last). It first checks if the passed inc outForChar is '\0', if not then there should be no separation in between each piece of data. If so, then it will be outputted with the outForChar before each piece of data. I am trying to figure out how to start on this, and wanted to know how I can approach this? This is my work so far, and I know it is not correct by any means so I would really appreciate any pointers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
T* i;
if (outForChar == '\0')
{
for (i = first; i != last; ++i)
{
std::cout << i;
}
}
else
{
for (i = first; i != last; ++i)
{
std::cout << outForChar << i;
}
}
Does it look good? I also tried the const auto way but for some reason my compiler is having an issue with the lambda function so I went with another way.