Skip to main content
Added code formatting
Source Link
Mark Rotteveel
  • 110.3k
  • 240
  • 160
  • 232

Null-terminate a string is something you won't have to deal with with std::stringstd::string. Firstly, every function that accepts std::stringstd::string already knows the length and does not require NULLNULL termination. Secondly, std::stringstd::string has a c_str()c_str() wrapper that provides a NULLNULL-terminated string for you, so you don't have to screw around with it. Just set the string to the length you want with resize and it's done.

Null-terminate a string is something you won't have to deal with with std::string. Firstly, every function that accepts std::string already knows the length and does not require NULL termination. Secondly, std::string has a c_str() wrapper that provides a NULL-terminated string for you, so you don't have to screw around with it. Just set the string to the length you want with resize and it's done.

Null-terminate a string is something you won't have to deal with with std::string. Firstly, every function that accepts std::string already knows the length and does not require NULL termination. Secondly, std::string has a c_str() wrapper that provides a NULL-terminated string for you, so you don't have to screw around with it. Just set the string to the length you want with resize and it's done.

Source Link
Puppy
  • 147.5k
  • 40
  • 271
  • 481

Null-terminate a string is something you won't have to deal with with std::string. Firstly, every function that accepts std::string already knows the length and does not require NULL termination. Secondly, std::string has a c_str() wrapper that provides a NULL-terminated string for you, so you don't have to screw around with it. Just set the string to the length you want with resize and it's done.