#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string str; //Declare a string
getline(cin,str); //Input a line
reverse(str.begin(),str.end()); //make the string reverse
cout<<str; //Output
return 0;
}
getline(cin,str)输入一行
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
char c[6] = { 'a','b','c','d','e','f' };
for (int i = 0; i < 6; i++)
cout << c[i] << " ";
cout << endl;
reverse(c,c+6); //直接替换字母
for (int i = 0; i < 6; i++)
cout << c[i] << " ";
cout << endl;
system("pause");
return 0;
}
一定要加上system(“pause”)否则会闪退
#include "stdafx.h"
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<char>v;
for (int i = 0; i < 6; i++)
v.push_back('a' + i);
for(int i = 0; i < 6; i++)
cout << v[i] << " ";
cout << endl;
reverse(v.begin(), v.end());
for (int i = 0; i < 6; i++)
cout << v[i] << " ";
cout << endl;
system("pause");
return 0;
}
容器的翻转