copy_if
필터를 사용하는 방법은 인덱스의 특정 배수를 str
으로 필터링하는 것입니다.`copy_if` 필터를 사용하여 인덱스의 특정 배수를 필터링하십시오.
str
은 "1000020000300004000050000"이고, newStr
은 "12345"입니다. 1 따르면
은 3은 5 * 2 등
소스 코드, 5 * 0, 2은 5 * 1이다 :
std::string str("1000020000300004000050000");
std::string newStr;
std::copy_if(str.begin(), str.end(),
std::back_inserter(newStr),
[] (char c) {
// Some specific rule I want to return.
return ...;
}
);
이상적인 코드 :
std::copy_if(str.begin(), str.end(),
std::back_inserter(newStr),
[] (char c) {
// I can get the index of iteration.
return (index % 5 == 0);
}
);
간단한 for 반복문에 어떤 문제가 있습니까? –
'copy_if'에서 같은 것을 할 수 있는지 알고 싶습니다. 귀하의 의견에 감사드립니다. :) – Husky