文字列を逆にするコードを書きました
#include < iostream >
#include < cstring >
using namespace std;
string Reversal(char * s);
int main()
{
char str[25];
cout << "Enter a Name :";
cin.get(str, 25);
cout << "You have entered: " << str;
cout << "\nReversed : " << Reversal(str);
return 0;
}
string Reversal(char * s)
{
int count = strlen(s);
char temp[count];
for (int i = 0; i < count; i++)
{
temp[i] = * (s + (count - 1) - i);
}
return temp;
}
以下のリンクを参照して、cin が空白を入力として受け取るようにします。
しかし、出力にはいくつかのジャンク文字が表示されていますか? なぜそうなのでしょうか?