dev dev c++程序在输入字母时立即关闭
dev Dev C++ program closes immediately when entering letters
输入字母后程序立即关闭。它显示了其余的代码,但我不能输入它的其他部分。当输入字母时,程序立即关闭,但当输入数字时,程序保持不变,直到程序应该显示复制信息的部分。我试过把getchar();
放在每个cin<<a;
之后,但它跳过了行,我只能输入一些信息。这是我的代码:*我是个新手,这是我写过的最长的代码。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
string a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,y,z;
cout<<"Enter Your Name:";
cin>>a;
cout<<"Enter Your Gender:";
cin>>z;
cout<<"Enter Your Age:";
cin>>b;
cout<<"Enter Your Address:";
cin>>c;
cout<<"Enter Your School:";
cin>>d;
cout<<"Enter Your Nickname:";
cin>>e;
cout<<"Enter Highest Educational Attainment:";
cin>>f;
cout<<"What are your skills?:";
cin>>g;
cout<<"How many years experience do you have in this field?:";
cin>>h;
cout<<"What kind of people would you like to have in the workplace?:";
cin>>i;
cout<<"What good values do you have?:";
cin>>j;
cout<<"What bad values do you have?:";
cin>>k;
cout<<"When is your birthday?:";
cin>>l;
cout<<"What is your Father's name?:";
cin>>m;
cout<<"What is your Mother's name?:";
cin>>n;
cout<<"Do you have any children?:";
cin>>o;
cout<<"What is your eye color?:";
cin>>y;
cout<<"What do you dislike?:";
cin>>p;
cout<<"How many are you in the family?:";
cin>>q;
cout<<"What is your favorite food?:";
cin>>r;
cout<<"Your name is:"<<a<<endl;
cout<<"You are a:"<<z<<endl;
cout<<"You are"<<b<<cout<<"years old."<<endl;
cout<<"You live in:"<<c<<endl;
cout<<"You studied in:"<<d<<endl;
cout<<"Your nickname is:"<<e<<endl;
cout<<"Your highest educational attainment is:"<<f<<endl;
cout<<"Your skills are:"<<g<<endl;
cout<<"You have"<<h<<cout<<"years of experience in this field."<<endl;
cout<<"You would like to have"<<i<<cout<<"in the workplace."<<endl;
cout<<"The good thing is, you are:"<<j<<endl;
cout<<"The bad thing is, you are also:"<<k<<endl;
cout<<"Your birthday is in:"<<l<<endl;
cout<<"Your father is:"<<m<<endl;
cout<<"Your mother is:"<<n<<endl;
cout<<"You have"<<o<<cout<<"children."<<endl;
cout<<"You have"<<y<<"eyes."<<endl;
cout<<"You dislike:"<<p<<endl;
cout<<"You are"<<q<<cout<<"in the family"<<endl;
cout<<"Your favorite food is:"<<r<<endl;
return 0;
system ("pause");
}
*编辑:将float
替换为string
,并在代码开头添加#include <string>
。现在唯一的问题是程序在应该显示输出时关闭,并且在输入中输入空格时,下一个问题在一行中。
如果x是float类型或integer类型
std::cin >> x;
如果std::cin开头的字符不能作为浮点数或整数类型的前缀,则不从std::cin中读取字母。
所以x保持为0,你的输入流保持不变。
下一个
std::cin >> y;
如果y为浮点型或整型,则会发生相同的行为:y保持为0,并且您的输入流std::cin仍然以浮点型或整型不能读取的字符开始。
此行为将一直持续到程序结束
float a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,y,z;
变量a
和其他float
类型的。这意味着它们可以存储1,10.0,12.3546
等值。一旦您为data type
输入任何无效字符,该程序将退出。
如果你想运行你的程序,尝试声明所有的变量为std::string
,并通过getline
输入,如getline(std::cin,var)
。
p。S:我假定var
的类型是string
。
相关文章:
- 请发现它在 dev 中工作的错误,但在 hackerrank 中不起作用
- 无法在 dev-c++ 上编译程序?
- Dev c++ mingw 不再编译
- 如何在 Windows 上将bcrypt_gensalt与 /dev/urandom 一起使用?
- 我正在使用dev c ++,但收到错误(C++98'array'必须由构造函数初始化)
- dev Wx Dev C++ vs Graphics.h?
- dev如何在C++中比较二进制数
- 在linux中为c++dev配置VSCode
- DEV C++ 第 69 行 [错误] ISO "for" 范围更改了"i"的名称查找 [-允许]
- dev在试图从dev c++mingw 4.8.1中的文件读取时接收分段错误
- 我有一个C++函数,它在Dev C++中编译,但在G++中不编译
- 写入/dev/ttyS0后读取0字节
- 如何将 stderr 重定向到 /dev/null
- 如何创建C++DLL(使用DEV -C++)并在MT4脚本中使用(逐步)
- auto 关键字在 Dev c++ 中不起作用
- 从 win 7 升级到 Win 10 后,出现 Dev-C++ makefile.win 编译错误
- 如何检测 ofstream 是否正在写入 /dev/null
- 如何将 libproxy-dev 链接到现有的 cmake 项目(C++)?
- 在哪里调用主函数(dev c ++)
- mmap with /dev/input/event*