it is a simple program that separates two 5 letter words, with a space after each letter, and as the title says, after it successfully compiles, it doesn't run.
#include"Letras.h"
#include<iostream>
int main()
{
Letras letra1;
Letras letra2;
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;
return 0;
}
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.