问一个关于c++ input 的问题。。
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 2 楼,分 1 页, 当前显示第 1 页 : 本帖树形列表 : 刷新 : 返回上一页
<<始页  [1]  末页>>
作者:我行故我 (等级:5 - 略有小成,发帖:1333) 发表:2003-05-12 14:31:51  楼主  关注此帖
问一个关于c++ input 的问题。。
problem:
input three lines: first line has a number
second line have two numbers
third line has a string of characters( the number of characters is not more than 1000)

my code:


# include<iostream.h>
int main(void){
int a;
cin>>a;
cout<<a<<"\n";

int x, y;
cin>>x>>y;
cout<<x<<" "<<y<<"\n";

char str[1001];
cin.getline(str, 1000);
cout<<str[2]; /*I put this line here to check whether the third line of input is read*/

return 0;
}

sample input and output:
first line input: 1
output: 1 // this is correct
second line input: 2 1
output: 2 1// this is also correc
but after the output 2 1 is displayed in the screen, the program suddenly end after prompting two blank lines..


the whole process is like this:
@sf3:~/c_programming[591]$ ./a.out
1
1
2 1
2 1

@sf3:~/c_programming[592]$



what is wrong with my code?
can anyone enlighten me?



Don't forget to always have a dream
我曾是孤单的飞鸟
飘荡在远方的天空
如今我已飞得太久
才知道我就是春天
我用力地挥动翅膀
开始寻找家的方向
我用力地挥动翅膀
溶进这宽阔的天空
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
作者:我行故我 (等级:5 - 略有小成,发帖:1333) 发表:2003-05-13 17:41:58  2楼
问一个关于c++ input 的问题。。problem: input three lines: first line has a number second line have two numbers third line has a string of characters( the number of characters is not more than 1000) my code: # include int main(void){ int a; cin>>a; couty; cout (more...)
多谢kikicoco 和 魅力十足
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版所有回复从这里展开收起列表
论坛导航 -> 华新鲜事 -> 求学狮城 | 返回上一页 | 本主题共有 2 篇文章,分 1 页, 当前显示第 1 页 | 回到顶部
<<始页  [1]  末页>>

请登录后回复:帐号   密码