std::cout << " La palabra 1 se separa en : ";
letra1.establecerLetras( "cosas" );
std::cout << " \n\nLa palabra 2 se separa en : ";
letra2.establecerLetras( "voces" );
std::cout << std::endl;
This is the error I get at when I run the program:
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 1) > this->size()
(which is 0) Aborted (core dumped) process returned 134 (0x86) execution time : 0.203 s
press ENTER to continue.
This is right at the start of execution, the string miPalabra is empty, its size is zero. At line 23 it tries to obtain a substring starting at position 1. Because position 1 does not exist (the string is empty), an exception is generated and the program terminates.
I'm not sure exactly what the program is supposed to do. Could you give an example of input and required output please.
Or use a traditional for-loop with a count from 0 to count<miPalabra.size(), accessing each character in the string. There's no need for substrings, and it should be fairly simple, just 2 or 3 lines of code rather than twenty or thirty.