首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一组连续的数如何储存进数组

2012-04-03 
一组连续的数怎么储存进数组具体说,就是用键盘连续的输入一组数,象16783257.中间用空格格开,按回车就直接

一组连续的数怎么储存进数组
具体说,就是用键盘连续的输入一组数,象1   6   7   8   32   57.中间用空格格开,按回车就直接把这组数储藏到一个数组中.

[解决办法]
#include <iostream>
#include <sstream>

int main()
{
using namespace std;
char tmp[255];
cin.getline(tmp,255);
stringstream ss(tmp);
int arr[20];
for(int i = 0;!ss.eof() && i < 20;++i)
ss> > arr[i];

//输出测试
for(int i = 0;i < 20;++i)
cout < <arr[i] < < " ";
cout < <endl;
}

[解决办法]
输入:
1 6 7 8 32 57 回车
输出:
1 6 7 8 32 57 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460
-858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -858993460 -85
8993460
因为数组没初始化,所以是-858993460。

热点排行