I want to remove the first character of a string using memmove
Example, a std::string might contain:
./Folder/File.txt
I want to remove the .
I am doing:
if (newStr[0] == '.')
{
memmove(newStr, newStr+1, strlen(newStr));
}
and getting an error: error: no match for 'operator+' in 'newStr + 1'
What mistake am I making?
UPDATE: oh, I think I should be using char* this wont work on a std::string
It appears like your newStr is a std::string, in this case you should use newStr.erase(0,1);
See this site for more information about erase
memmoveis only valid if you are dealing with a buffer directly (char* or char[]). If your type is std::string, use the function that’s meant for it (erase) and don’t trymemmoveon the c_str.