This post will discuss how to remove n characters from the start of a string in C++.

1. Using string::erase

The standard solution to erase characters from a string is using the string::erase function. It is overloaded to accept the index of the first character to be erased and the number of characters to erase. It can be invoked as follows:

Download  Run Code

2. Using string::substr

Note that calling the string::erase function on the string modifies the original string. To construct a new string, we can use the string::substr function, as shown below.

Download  Run Code

That’s all about removing n characters from the start of a string in C++.