我的 cin>> 被跳过/忽略
My cin>> is being skipped/ignored
我的cin >> OneDecision;
不断被跳过,然后它只是在那里结束了整个程序。
我试过cin.getline(OneDecision, 40)
,但无论如何。它行不通,我不知道为什么不行。除非我修复它,否则我无法继续游戏。
这是针对课堂作业的,它将是一个简短的基于文本的恐怖游戏。如果我能得到一些帮助,那就太好了。我是业余爱好者,怜悯。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <iomanip>
#include <limits>
using namespace std;
int main()
{
char player1 [40],
char fear [40];
char friend1 [40];
char friend2 [40];
int start;
char option [40], option2 [40], option3 [40], option4 [40];
char OneDecision [40], OneDecision2 [40];
cout << "Hey.... what's your name?n";
cin.get(player1, 40);
cout<< "Well, " << player1 << ". What is your biggest fear?n";
cin >> fear ;
cout <<"Name one friend.n";
cin >> friend1;
cout << "Name another friend... or make one up if you have none.n";
cin >> friend2;
cout<< "Are you ready to play?n 1. Yes or 2. No.n";
cin >> start ;
if (start == 1)
{
cout << "You'll later regret it...n You have entered HORROR HOUSE.";
}
else if (start == 2)
{
cout << "I don't blame you. Why the hell would you want to enter a horror house to be honest...nnnn";
cout << " END GAME.";
}
Sleep(2500);
system("cls");
cout<< "You, " << friend1 << " and " << friend2 << " are staying at the mansion " << friend1 << "'s family recently nbought.";
cout << "It's night, and you are in your room sleeping.nWhen you here a loud noise, a thump.nYou get out of bed, and look around to see if something fell.n";
cout << "The door you though you closed was left open, and but other than that nothing is wrong.nnnnn";
Sleep (12000);
cout << " But then you hear a horrible scream from outside.nn";
cout << " Run to window and see? Or Run to " << friend1 << "'s room?n";
cin.get(option, 40);
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n'); // The program terminates at this line, I've tried other ways of saying for it to ignore the next line but none of them worked, this was the last thing I tried.
if (string(option) == "run to window" || string(option) == "window")
{
cout << " n You run to the window and see " << friend1 << " laying dead on the ground outside.n";
cout << " Go downstairs and out the house toward" << friend1 << "?n Or run to " << friend2 << "'s room to wake them up." ;
cin.get(OneDecision, 40);
if (OneDecision == "go downstairs")
{
cout << "You are running downstairs. You run out of the house, and search you're backyard for" << friend1 << ", but , you can't find their body.";
}
return 0;
答案
您需要更改:
if (option == "run to window" || "window")
自:
if (string(option) == "run to window" || string(option) == "window")
相关文章:
- 在fstream期间忽略空行
- 概念TS检查忽略私有访问修饰符
- C++宏忽略之后的内容
- 不知道某个东西是否被忽略会引入未定义的行为吗
- clang整洁10忽略了我的NOLINT命令
- EASTL矢量<向量<int>>连续的
- If语句在c++中被忽略
- 错误:在为指针赋值时,void值没有被忽略
- 为什么stream::忽略未按预期工作
- Craps游戏问题,忽略if语句
- c++字符串中的字符将被忽略
- 为什么在 x64 中忽略__stdcall调用约定?
- 为什么C++的文件 I/O 在读取文本文件时忽略初始空行?我怎样才能让它不这样做?
- MSVC 忽略 [[maybe_unused]] 的功能?
- 警告:在函数返回类型 [-Wignore 限定符] 时忽略类型限定符
- Pytorch torch.cholesky忽略异常
- C++ - 忽略并从其他文件获取数据
- 如何忽略输入流中的某些字符?
- PangoLayout 中忽略的新行
- 如何在Qt 4.8中阻止/忽略/丢弃早于特定超时的用户输入事件