我是新來的代碼和這個網站,所以請原諒我,如果我忽略了明顯的東西。我一直在嘗試用C++編寫一個簡短的小遊戲,並且我需要接受用戶輸入。我想收錄一個以上的單詞,所以我的書推薦的cin>>
命令是正確的。我通過研究發現的最好的東西是getline(cin,var);
命令。我可以很容易地在小型測試中工作,但是當我將其應用到我的500線遊戲中時,它無法工作。它將直接跳過那段代碼而不用等待用戶輸入,並將變量設置爲空格。顯然,我不會包含整個代碼,但這裏有一點問題,還有我的標題。干擾getline函數的東西?
#include <cstdlib>
#include <windows.h>
#include <iostream>
#include <string>
using namespace std;
string poemend;
int heading;
int poem()
{
system("CLS");
cout<<"This poem is almost done, you just can't seem to find the perfect last word.\n";
cout<<"You can see several of your discarded endings. Most recently, 'pain'.\n\n";
cout<<"How about another go?\n>";
getline(cin,poemend);
system("CLS");
cout<<"The Prophet's old parrot spoke much of all things,\n";
cout<<"but when asked about love, squawked only ";
cout<<poemend<<" .\n\n";
Sleep(6000);
cout<<"You decide it could still use some work";
Sleep(3000);
heading = 6;
}
再次,這完美的作品,如果我藉此到新的空白頁面,所以我真的不知道是什麼的方式獲得。如果需要,我會很樂意回答有關代碼的任何問題,併發布更多有用的信息。非常感謝您花時間閱讀本文!
請使用一個小缺口 –
,你沒有向我們展示的是問題的代碼。 – 0x499602D2
您向我們展示的代碼沒有問題。你能發佈更多與流有關的代碼嗎? – 0x499602D2