So I have my class called array
and I want to return it as a formatted string, like this: [first, second, third, ..., last]
. Now I wrote the method that is trying to do so:
std::string& array::to_string()
{
char buffer[1];
std::string s("[");
for (auto &x: *this)
{
if (&x == this->end()) s += _itoa_s(x, buffer, 10) + "]";
else s += _itoa_s(x, buffer, 10) + ",";
}
return s;
}
And yes, I've included <string>
. Now, in the other part of my program I use std::cout << myArray.to_string() << '\n'
. The error I get (during the execution) is just Visual Studio throwing me to stdlib.h
header and showing this part of it:
__DEFINE_CPP_OVERLOAD_SECURE_FUNC_1_1(
_Success_(return == 0)
errno_t, _itoa_s,
_In_ int, _Value,
char, _Buffer,
_In_ int, _Radix
)
What am I doing wrong?