Hey all, I am trying to fix this so a string entered like "I like cake" will be displayed on separate lines such as:
I
L
I
K
E
C
A
K
E
I can't seem to get it to work. If I enter a space in the string then the output becomes gibberish, also I have to keep setting the defined limit of the string with the max variable....which is not good.
Can someone tell me what I am missing in this piece of code?
Code:#include <iostream> #include <string> using namespace std; int main() { string input = ""; int i = 0; int max = 10; //make loop not go on forever cout << "Enter in a string to separate!" << endl; cin >> input; for(i=0; i<=max; i++) //Take each char element in the array and display it on it's own line { cout << input[i] << endl; } cout << "End..."; return 0; }