I have a string..."APPLES" and i'm having difficulty using substring to effectively manipulate the string. My goal is to add a '-' every 3 characters. My problem is that when "APPLES" goes through, it returns "APP-ES-" which is incorrect, I'm trying to make it return "APP-LES-" any suggestions? Here is my code thus far...
for(int j = 0; j <= str.length(); j++){
str_substr += str.substr(j,j+3);
str_substr = str_substr + '-';
j = j+3;
cout << str_substr;
}
j++andj = j + 3is horrible. For your fix, don't runjup to the end of the string