佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1205|回复: 4

C++ 问题

[复制链接]
发表于 13-1-2009 08:59 PM | 显示全部楼层 |阅读模式
为什么我的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;


}
回复

使用道具 举报


ADVERTISEMENT

发表于 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);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 18-12-2025 01:44 AM , Processed in 0.101847 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表