Incrementing the last character
w [ w . size ( ) - 1 ] ++ ; int m = w . size ( ) ; if ( m == n ) { string str ; for ( int i = 0 ; i < w . size ( ) ; i ++ ) { str += S [ w [ i ] ] ; } cout << str << endl ; }