我试图编写一个程序,它将字符串中的消息存储回字符数组中,并且每当我运行它时,它有时会成功向后写入,但有时会将随机字符添加到末尾此:Random ascii char的出现
输入:写这个向后
sdrawkcab SIHT etirw
#include <iostream>
#include <string>
using namespace std;
int main()
{
string message;
getline(cin, message);
int howLong = message.length() - 1;
char reverse[howLong];
for(int spot = 0; howLong >= 0; howLong--)
{
reverse[spot] = message.at(howLong);
spot++;
}
cout << reverse;
return 0;
}
C++不支持VLA – ipc 2012-03-20 16:11:58