After running the program below, I get an extra 0 (zero) after the output.
Is this a Null character at the end of the string? And how can i remove this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <initializer_list>
void PrintIList(std::initializer_list<std::string> add)
{
int Total = 0;
for (auto beg = add.begin(); beg != add.end(); ++beg)
{
std::cout << *beg;
}
std::cout << Total;
}
int main()
{
std::initializer_list<std::string> ili = {"Some ","sample ","text."};
PrintIList(ili);
}
You are declaring Total = 0 in that function, and then you are printing it after the for loop. The initializer list has nothing to do with this number.