I am supposed to 1 space between letters and 3 spaces between words in a string (not c-style string). I know how to check for letters and add a space between each one. The problem is I'm not sure how to add the space between letters without accidentally erasing a letter.
for example....
"hey"
would become
"h y" from my code below.
Any tips how I can accomplish "h e y"?
Code:#include<iostream> #include<string> #include<cctype> using namespace std; int main() { string one = "hey you"; //Checks for letters and inserts 1 space next to each letter until it reaches the end of the string for (int i=0; j < one.length(); i++) { if (isalpha(one[i])) //if character at one[i] is an alphabet, insert a space at one[i+1] one[j+1] = ' '; } cout << one << endl; return 0; }



LinkBack URL
About LinkBacks



CornedBee