가능한 중복 :
Splitting a string in C++C++에서 PHP의 explode() 함수와 동일한 기능이 있습니까?
은 PHP, 상기 explode()
함수는 문자열 걸리며 지정된 분리하여 각 분리 요소 배열로 그것을 들어온다.
C++에는 동일한 기능이 있습니까?
#include <string>
#include <vector>
#include <sstream>
#include <utility>
std::vector<std::string> explode(std::string const & s, char delim)
{
std::vector<std::string> result;
std::istringstream iss(s);
for (std::string token; std::getline(iss, token, delim);)
{
result.push_back(std::move(token));
}
return result;
}
사용법 :
auto v = explode("hello world foo bar", ' ');
참고 : 출력 반복자에 쓰기 제리의 생각은 C 더 관용적 인 @ ++
아니요, 그렇지만 자체 구현을 작성하기는 쉽습니다. –
[boost/algorithm/string.hpp]의 boost :: split' (www.boost.org/doc/html/string_algo.html) – Praetorian
@KerrekSB이 문제가 해결되기 전에 답변을 작성해야한다고 생각합니다. –