C+ + 编程问题
从键盘将一个字符串输入到字符数组中,按反序存放。例如输入“Abcd e”,则输出“e dcbA”。
2018-11-07 21:07
字符串反转
2018-11-08 01:23
程序代码:#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
int main( void )
{
// 先输入,这没什么好说的
string s;
getline( cin, s );
// 然后可以先反序,再输出
//std::reverse( s.begin(), s.end() );
//cout << s << endl;
// 或者不反序,而是反着输出
copy( s.rbegin(), s.rend(), std::ostream_iterator<char>(cout) );
}
2018-11-08 08:52
2018-11-08 16:51