我已尽力修复我的逻辑,但我无法检测到错误。我不能使用 [] 或任何其他高级功能,因为我还没有介绍它们。如果可以的话,请告诉我我的错误。请不要给我负分,因为我已经尽力了,我的错误没有意义!谢谢。
该脚本应该反转输入字符串:例如:hi to ih。
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
void ReverseString(string &aString);
int main(){
string info;
cout << "What's your string?" << endl;
getline(cin, info);
cout << info << " compare with: " << endl;
ReverseString(info);
cout << info << endl;
system("pause");
return 0;
}
void ReverseString(string &aString)
{
for(int i = 0; i < aString.length(); i++)
{
int u = aString.length() - 1 - i;
string temp = "";
temp += aString.at(aString.length() - 1 - i);
if(u == 0 )/* when aString.length() - 1 - i == 0, the last char will have been processed*/
{
aString = temp; /*store temp into aString; when its value changes, it is passed into info's value*/
}
}
}