This is a debug program
#include <iostream>using namespacestd;classSolution { Public: voidReplacespace (Char*STR,intlength) { if(str = = NULL | | length<=0) return; intLength_origin =0; intblank =0; while(*str! =' /'){ if(*str = =' ') {Blank++; Length_origin++; STR++; } Else{Length_origin++; STR++; Continue; }} cout<<'a'<<Endl; intLength_new = length_origin+2*Blank; cout<<'a'<<Endl; if(Length_new >length)return; Else{cout<<'b'<<Endl; Char*str_new = str+2*Blank; cout<<'b'<<Endl; while(Str_new! =str) { if(*str = =' '){ *str_new ='0'; * (str_new-1) ='2'; * (str_new-2) ='%'; Str_new= Str_new-3; STR--; } Else{ *str_new =*str; Str_new--; STR--; } } } }};intMain () {//cout<< ' a '; CharStr[] ="We are happy"; cout<<str<<Endl; Solution Replace; Replace.replacespace (str, -); cout<<'a'; cout<<'a'<<Endl; cout<<'a'<<Endl; cout<<str<<Endl; return 0;}
The effect of the output is:
we are Happyaabbaaawe%20are%20happy
C + + input and output is cin,cout
cout back plus Endl will add a carriage return after the output ' \ n ', if not added Endl, the output below will be followed by one of the above output
C + + input and output