array 及 vector 的使用

撰写一个程序,从标准输入装置读取一串整数,并将读入的整数依次置入array及vector,然后遍历这两种容器,求取数值总和,将总和及平均值输出至标准输装置。


// 1_6.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 
#include 

using namespace std;

int main(int argc, char* argv[])
{

	int a[5];
	vector a_v(5);
	int total=0,total_v=0;
	//int* p;
	//p=&a_v[0];

	for(int i=0;i<5;i++)
	{
		cin >> a[i];
		a_v[i]=&a[i];
		
	}

	for(int j=0;j<5;j++)
	{
		total += a[j];
		total_v += *a_v[j];
	}

	/*for(int* p=&a_v[0];p


你可能感兴趣的:(C&C++)