【发布时间】:2016-12-14 03:37:52
【问题描述】:
当我输入一个字母时,我的程序立即关闭。它显示了代码的其余部分,但我没有进入它的其他部分。程序在输入字母时立即关闭,但在输入数字时仍然存在,直到程序应该显示复制信息的部分。我试过在每个cin<<a; 之后加上getchar();,但它会跳过行,我只能输入很少的信息。这是我的代码:
* 我是一个极端的新手,这是迄今为止我写过的最长的代码。
#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>。现在唯一的问题是程序在应该显示输出时关闭,当在输入中输入空格时,下一个问题在一行中。
【问题讨论】:
-
您正在读取浮点数,而不是字符。要读取字符,请将
float更改为string并在开头添加#include <string> -
如果要输入字母,为什么要提取值到
floats? -
只是为了将来:为变量使用更明确的名称
-
@V. Kravchenko
#include <string>工作,我现在可以输入字母,但它仍然在应该复制输入的部分关闭。此外,在输入中添加空格时,下一个问题会变得混乱 -
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;哦,我的....