사용자가 "입력"을 누르고 루핑을 계속 할 때 내 프로그램이 인식하도록합니다. 그러나 프로그램에서 "입력"을 식별하는 방법을 파악할 수 없습니다."확인"
string enter;
string ent = "\n";
dice d1;
cout << "To start - Press enter" << endl;
getline (cin, enter);
while (enter == ent)
{
d1.throw_dice();
d1.draw_dice();
cout << "Try again, press enter" << endl;
getline (cin, enter);
}
cout << "Thank you for playing"<< endl;
그리고이 하나 : 두 가지 방법을 시도
string enter;
dice d1;
cout << "To start - Press any key and enter" << endl;
getline (cin, enter);
while (enter == "\n")
{
d1.throw_dice();
d1.draw_dice();
cout << "Try again, press enter" << endl;
getline (cin, enter);
}
cout << "Thank you for playing"<< endl;
내가 그 문자열이 떨어져 "N \"을 던져 알고 있지만, 캔트 정말 해결하는 방법을 찾을 수 있습니다.
PS는 :
나는 해결책을 발견 하였다. 그러나 나는 여전히 더 나은 선택이 있어야한다고 생각합니다.
while (cin.get() == '\n')
{
d1.throw_dice();
d1.draw_dice();
cout << "Try again, press enter! Or press any other key and enter" << endl;
if (cin.get() != '\n')
break;
}
cout << "Thank you for playing"<< endl;
return 0;
}
질문을 C++로 태그 지정하여 올바른 사람을 볼 수 있습니다. –