根據您輸入的單詞數量,回圈如何回傳訊息 Enter # when done MORE 而不是一次?EG 輸入一個字母它會回圈訊息輸入 # 完成后但如果你輸入什么?它回傳它 Enter # when done x4 ....word 中相同數量的字母。我是來自 c 的 c 新手,所以我很困惑。不要擔心代碼中的其他內容我需要幫助。謝謝 :)
#include <iostream>
#include <stdio.h>
int main() {
char sup;
while (sup != '#') {
std::cout << "Hi\n";
std::cout << "Enter # when done";
std::cin >> sup;
if(sup == '#') {
std::cout << "Ok you want to go.";
}
}
std::cin.get();
}
uj5u.com熱心網友回復:
std::string 示例
// preferably do not include stdio.h in C programs
#include <string>
#include <iostream>
int main()
{
std::string input; // use standard library string class
while (input != "#")
{
std::cout << "Hi\n";
std::cout << "Enter # when done : ";
std::cin >> input;
if (input == "#")
{
std::cout << "Ok you want to go.\n";
}
}
return 0; // <== important to otherwise your program is ill-formed
}
uj5u.com熱心網友回復:
當您在 while 回圈中設定時(sup != '#'),它將接受輸入字符,直到您鍵入#。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/399555.html
