Split a character string based on change of character: Difference between revisions

Updated C++ solution
(Added C++ Implementation)
(Updated C++ solution)
Line 213:
=={{header|C++}}==
<lang cpp>
// Solution for http://rosettacode.org/wiki/Split_a_character_string_based_on_change_of_character
#include<string>
#include<iostream>
std::stringauto spliter(const std::string &input) {
boolauto firstCommaPast = false;
std::string res ="";
charauto prev = '\0';
for(std::string::iteratorauto it = input.begincbegin(); it != input.endcend();++it) {
if(*it!=prev) {
if(!firstCommaPast) {
firstCommaPast = true;
} else {
res+=", ";
}
}
Line 234 ⟶ 235:
 
int main() {
std::stringauto input = R"(gHHH5YYgHHH5 ))YY++,,,///\)";
std::string res = cout<<spliter(input);
} </lang>
std::cout<<res;
}
</lang>
{{out}}
<pre>g, HHH, 5, , )), YY, ++, ,,,, ///, \</pre>