std::string s = "Hola-perro-Cosa"; int init = 0; int end = 0; while( end = s.find("-", init), end >= 0 ) { std::cout << s.substr(init, end - init) << ' '; init = end + 1; } std::cout << s.substr(init);