ProgrammingProjectList
ProgrammingProjectList copied to clipboard
C/C++·的翻转文字列
trafficstars
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str("");
string newStr("");
cout << "input your message :";
cin >> str;
for (int i = (str.length() - 1); i >= 0; i--) {
newStr += str[i];
}
cout << newStr << endl;
cin.ignore(6);
}
啊这~贴代码尽量用上 ``` 格式来标注代码例如:
#include <iostream>
#include <string>
using namespace std;
string reverse(string str) {
string newStr;
for (int i = str.length() - 1; i >= 0; --i) {
newStr += str[i];
}
return newStr;
}
int main()
{
string str;
cout << "input your message :";
cin >> str;
cout << reverse(str) << endl;
return 0;
}
啊这~贴代码尽量用上 ``` 格式来标注代码例如:
#include <iostream> #include <string> using namespace std; string reverse(string str) { string newStr; for (int i = str.length() - 1; i >= 0; --i) { newStr += str[i]; } return newStr; } int main() { string str; cout << "input your message :"; cin >> str; cout << reverse(str) << endl; return 0; }
好的,谢谢,现在加上了