I’m in C++. And I’m trying to append a char array to a C++ string. The only thing is that this array can have every possible value, negative, positive and 0. So when I assign this array to the string, it stops at some point because it found a 0 value.
1) Can string append these values? Or do they have to be strictly from 1 to 127?
If true,
2) Is there a way to keep the string assignment going even even if it finds a 0?
I’m in C++. And I’m trying to append a char array to a C++
Share
The
string::append( const char* s, size_t n )overload forappend()should do what you want. Assuming thatcpp_stringis yourstd::stringvariable or reference andc_string_ptris your pointer to an array of characters:Note however, the
std::stringis a typedef forstd::basic_string<char>. Sincecharmight not be signed on your platform you might not get the comparison behavior you want. You should ensure thatcharis signed on your platform or you might want to use your own typedef to prevent problems if the platform (or build) changes in the future: