|
|
为什么我的program不能Accept space的?
以下是我写的program。。。
请各位大大教导。。。
#include<iostream.h>
void main()
{
char name[100];
int num1,num2,avg;
cout<<"Enter Your Name:";
cin>>name[100];
cout<<"Enter Number no.1 : "
cin>>num1;
cout<<"Enter Number no.2 : "
cin>>num2;
avg=num1+num2;
cout<<"\n\n\n\n\n\n";
cout<<"name = " <<name;
cout<<"Average = "<<avg;
} |
|
|
|
|
|
|
|
|
|
|
发表于 15-1-2009 09:40 PM
|
显示全部楼层
不知道你的程度到哪里所以直接跟你讲alternatives好了。。。
如果你要string with spaces 用scanf吧。。 |
|
|
|
|
|
|
|
|
|
|
发表于 16-1-2009 11:40 PM
|
显示全部楼层
cin 本身不会读取whitespace的, 用 cin.getline
string 的就用 getline |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 22-1-2009 01:55 PM
|
显示全部楼层
|
很感谢你们的帮忙,我的程度会到 looping 罢了。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 11-2-2009 06:47 PM
|
显示全部楼层
回复 4# 毛毛人 的帖子
program 通常分input, process, output
input, output 一定要懂
process 包括 selection statement, looping, function, array, pointer, ...
你的program问题在于input
cin>>name[100]; //是不可能的
对的是用
原帖由 onlylonly 于 16-1-2009 11:40 PM 发表
cin 本身不会读取whitespace的, 用 cin.getline
string 的就用 getline
cin.getline(name); |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|