"C++ 문자열 trim() 구현"의 두 판 사이의 차이

(새 문서: ==개요== ;C++ trim() 구현 ;C++ 문자열 trim() 구현 <syntaxhighlight lang='cpp' run> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main...)
 
잔글 (Jmnote님이 C++ trim() 구현 문서를 C++ 문자열 trim() 구현 문서로 이동했습니다)
(차이 없음)

2023년 9월 24일 (일) 15:19 판

1 개요

C++ trim() 구현
C++ 문자열 trim() 구현
#include <iostream>
#include <vector>
#include <algorithm> 
using namespace std;

int main() {
    string s = "  Hello, World  ";
    s.erase(s.begin(), find_if(s.begin(), s.end(), [](unsigned char ch) { return !isspace(ch); }));
    s.erase(find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !isspace(ch); }).base(), s.end());
    cout << '[' << s << ']'; // [Hello, World]
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}