옐그's 코딩라이프

[c++] erase() 문자열 내 문자 제거 본문

c++/개념정리

[c++] erase() 문자열 내 문자 제거

옐그멍이 2022. 7. 25. 14:05
더보기

erase(시작위치, 길이);

  • string 클래스에 있음
  • 시작위치와 길이(갯수)를 입력하여 사용
#include <iostream>
#include <string>
using namespace std;

int main(){
    string x = "yello2wgreen";
    x.erase(5,2);
    cout << x; //출력은 yellogreen
}

 

728x90