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
我曾是孤单的飞鸟
飘荡在远方的天空
如今我已飞得太久
才知道我就是春天
我用力地挥动翅膀
开始寻找家的方向
我用力地挥动翅膀
溶进这宽阔的天空