使用`memmove`删除std :: string的第一个字符

Jas*_*son 1 c++ string compiler-errors

我想删除字符串的第一个字符 memmove

例如,a std::string可能包含:

./Folder/File.txt

我想删除 .

我在做:

if (newStr[0] == '.')
{
    memmove(newStr, newStr+1, strlen(newStr));
}
Run Code Online (Sandbox Code Playgroud)

并收到错误: error: no match for 'operator+' in 'newStr + 1'

我犯了什么错误?

更新:哦,我想我应该使用char*这个不会工作std::string

ema*_*tel 6

看起来你的newStr是一个std :: string,在这种情况下你应该使用newStr.erase(0,1);

有关擦除的详细信息,请参阅此站点

memmove只有在直接处理缓冲区(char*或char [])时才有效.如果你的类型是std :: string,请使用它的意思(擦除)函数,不要尝试memmove使用c_str.