The following describes how to input a string in C ++ and output the characters in descending order. For more information, see
Use the character array method:
The basic idea is to first judge the character ending sign ''and then output it from this position.
Implementation Code:
Copy codeThe Code is as follows:
# Include <iostream>
Using namespace std;
Int main (){
Char a [50];
Cout <"please input a string :";
Cin>;
Int I = 0, k = 0;
While (I <50 ){
If (a [I] = ''){
K = I;
Break;
}
I ++;
}
Cout <"reverse order :";
For (; k> = 0; k --){
Cout <a [k];
}
Cout <endl;
Return 0;
}
Use the string method:
The basic idea is to use the strlen () function to determine the length of a character and then output it from the position of the length of the array.
Implementation Code:
Copy codeThe Code is as follows:
# Include <iostream>
# Include <string>
Using namespace std;
Int main (){
Char a [50];
Cout <"please input a string :";
Cin>;
Int k = 0;
K = strlen ();
Cout <"Reverse order :";
For (; k> = 0; k --){
Cout <a [k];
}
Cout <endl;
Return 0;
}