C++寻找String.Replace()

AK_*_*AK_ 1 c++ stdstring

我在C++中有一个char数组,它像{'a','b','c',0,0,0,0}

现在我把它改成一个流,我希望它看起来像"abc",其中有四个空格,我主要使用std :: stiring,我也有提升.我怎么能用C++做到这一点

基本上我认为我正在寻找类似的东西

char hellishCString[7] = {'a','b','c',0,0,0,0}; // comes from some wired struct actually...
std::string newString(hellishCString, sizeof(hellishCString));

newString.Replace(0,' '); // not real C++

ar << newString;
Run Code Online (Sandbox Code Playgroud)

Phi*_*ipp 10

用途std::replace:

#include <string>
#include <algorithm>
#include <iostream>

int main(void) {
  char hellishCString[7] = {'a','b','c',0,0,0,0}; // comes from some wired struct actually...
  std::string newString(hellishCString, sizeof hellishCString);
  std::replace(newString.begin(), newString.end(), '\0', ' ');
  std::cout << '+' << newString << '+' << std::endl;
}
Run Code Online (Sandbox Code Playgroud)