I think this should happen something like this:
string str("cadgfacbda"); for(int i = 0 ; i < str.size() ; i++) { cout << str[j]<<" "; if( i % 3 == 0 ) cout<<endl; }
This of course assumes that you will need a new line after every three elements. If you just need spaces, you can try this instead:
string str("cadgfacbda"); for(int i = 0 ; i < str.size() ; i++) { cout << str[j]; if( i % 3 == 0 ) cout<<" "; }
source share