文字列に文字列のメッセージを格納するプログラムを作成しようとしていましたが、実行するたびに正常に後ろに書きますが、他のときはランダムな文字を最後に追加しますこれ:ランダムなアスキー文字が表示されます
入力:この後方
を書き込む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