题目描述
写出一个程序,接受一个字符串,然后输出该字符串反转后的字符串。例如:
输入描述:
输入N个字符
输出描述:
输出该字符串反转后的字符串
输入例子:
abcd
输出例子:
dcba
- #include <iostream>
- #include<string>
- int main()
- {
- string str;
- cin >> str;
- for(int i=str.size()-1; i>=0; i--)
- cout<<str[i];
- }
【注意】: 如果写成char str[80], 则使用size()就会报错,另外也不需要这样声明string str[80];
————————————— 附录 ————————————————
如果要求的是对句子“This is an apple”进行反转,为“elppa na si sihT”
- cin>>str;
- for(auto it=str.crbegin(); it!=crend(); it++)
- {
- cout<<*it;
- }
见博客:http://blog.csdn.net/piniheaven/article/details/9454507