Having a string HelloHello how can I extract (i.e. omit) the first char, to have elloHello?
I've thought of .at() and string[n] but they return the value and don't delete it from the string
Having a string HelloHello how can I extract (i.e. omit) the first char, to have elloHello?
I've thought of .at() and string[n] but they return the value and don't delete it from the string
#include <iostream> #include <string> int main(int,char**) { std::string x = "HelloHello"; x.erase(x.begin()); std::cout << x << "\n"; return 0; } prints
elloHello Use erase
std::string str ("HelloHello"); str.erase (0,1); // Removes 1 characters starting at 0. // ... or str.erase(str.begin()); You should use substring. The first parameter indicates the start position. The second parameter string::npos means you want the new string to contain all characters from the specified start position until the end of the string.
std::string shorterString = hellohello.substr(1, std::string::npos);