Вы можете использовать функцию-член std::string
s find
, чтобы найти положение первого \n
, а затем его функцию erase
, чтобы стереть все char
s с begin()
до (и включая) найденного положение.
Пример:
#include <iostream>
#include <iterator>
#include <string>
void remove_first_line(std::string& s) {
if(auto idx = s.find('\n'); idx != std::string::npos) {
s.erase(s.begin(), std::next(s.begin(), idx+1));
}
}
int main() {
std::string text = "hello\nworld\nthis\nis\nfun\n";
std::cout << "----- before ----\n";
std::cout << text;
remove_first_line(text);
std::cout << "----- after ----\n";
std::cout << text;
}
Вывод:
----- before ----
hello
world
this
is
fun
----- after ----
world
this
is
fun