我試圖編寫一個程序,它將字符串中的消息存儲回字符數組中,並且每當我運行它時,它有時會成功向後寫入,但有時會將隨機字符添加到末尾此: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