How to append a char to a std::string?
y += d;
I would use +=
operator instead of named functions.
Use push_back()
:
std::string y("Hello worl");
y.push_back('d')
std::cout << y;
To add a char to a std::string var using the append method, you need to use this overload:
std::string::append(size_type _Count, char _Ch)
Edit : Your're right I misunderstood the size_type parameter, displayed in the context help. This is the number of chars to add. So the correct call is
s.append(1, d);
not
s.append(sizeof(char), d);
Or the simpliest way :
s += d;