STL string 삽입, 삭제, append, substr in c++
string push_back, pop_back, append, substr
#include <bits/stdc++.h>
using namespace std;
int main() {
string a = "My name is Purple. 2021Year.";
cout << "string a\'s last char is : " << a.back() << '\n';
cout << "string a\'s first char is : " << a.front() << '\n';
a.push_back('a');
cout << "after push_back is : " << a << '\n';
a.pop_back();
cout << "after pop_back is : " << a << '\n';
a = a + " September 21.";
cout << "after string append is : " << a << '\n';
cout << "after 19 index is : " << a.substr(19) << '\n';
cout << "after 0 index, 7 is : " << a.substr(0, 7) << '\n';
return 0;
}
- a.back() : 문자열의 맨뒤 문자를 가리킨다.
- a.front() : 문자열의 처음 문자를 가리킨다.
- a.push_back('a') : 문자열의 맨뒤에 문자를 삽입한다.
- a.pop_back() : 문자열의 맨뒤 문자를 삭제한다.
- a = a + "September 21." : 문자열을 append 한다.
- a.substr(19) : index 19이후로 모든 문자열을 빼낸다.
- a.substr(0, 7) : index 0이후로, 7개의 문자를 빼낸다.
Author And Source
이 문제에 관하여(STL string 삽입, 삭제, append, substr in c++), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@juwon9733/STL-string-삽입-삭제-append-substr-in-c저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)