输出以 space 开头
The output begins with space
我做了一个函数来反转字符串,但是反转字符串的输出总是向右移动一个字符。
#include <iostream>
#include <string>
using namespace std;
void reverse(string string1)
{
cout << endl;
for (int i = string1.size(); i >= 0; i--)
{
cout << string1[i];
}
cout << endl;
}
int main()
{
string string1;
getline(cin, string1);
reverse(string1);
system("pause");
return 0;
}
您的第一个输出是一个不存在的字符。
std::string
的漏洞抽象意味着您的第一次迭代正在打印 '[=11=]'
,这在您的配置中显然看起来像 space。
开始于 string1.size() - 1
。
我做了一个函数来反转字符串,但是反转字符串的输出总是向右移动一个字符。
#include <iostream>
#include <string>
using namespace std;
void reverse(string string1)
{
cout << endl;
for (int i = string1.size(); i >= 0; i--)
{
cout << string1[i];
}
cout << endl;
}
int main()
{
string string1;
getline(cin, string1);
reverse(string1);
system("pause");
return 0;
}
您的第一个输出是一个不存在的字符。
std::string
的漏洞抽象意味着您的第一次迭代正在打印 '[=11=]'
,这在您的配置中显然看起来像 space。
开始于 string1.size() - 1
。