我正在使用这个程序来实现单声道字母密码。我得到的问题是,当我输入纯文本时,它不会退出循环,当条件满足时,按下回车键。这里是我的代码。没有走出循环
int main()
{
system("cls");
cout << "Enter the plain text you want to encrypt";
k = 0;
while(1)
{
ch = getche();
if(ch == '\n')
{
break; // here is the problem program not getting out of the loop
}
for(i = 0; i < 26; i++)
{
if(arr[i] == ch)
{
ch = key[i];
}
}
string[k] = ch;
k++;
}
for(i = 0;i < k; i++)
{
cout << string[i];
}
getch();
return 0;
}
休息是否受到打击?如果不是,getche是否捕获换行符? – devshorts
@devshorts这就是它没有获得换行符的问题。 – james
有没有机会在Widnows机器上发生这个问题? – monksy