c++ 通过指针获取数据

#include "stdafx.h"
#include <vector>
#include <iostream>

using namespace std;

int main()
{
	vector<double> listdata = { 10.2,10.6,12.9 };
	for (size_t i = 0; i < listdata.size(); i++)
	{
		double* first = listdata.data() + i; //listdata.data() 首指针
		std::cout << *first << std::endl;
	}

	system("pause");
	return 0;
}

array 操作

#include "stdafx.h"
#include <vector>
#include <iostream>
#include <array>

using namespace std;

int main()
{
	array<double, 5> arr_data = { 10.2,10.6,12.9,3.12,6.9 };
	//double* first = arr_data.data(); // 首指针
	//std::cout << *first << std::endl;
	std::cout << &arr_data << std::endl; //取array地址

	//double first = arr_data[0]; //首元素
	//std::cout << first << std::endl;

	system("pause");
	return 0;
}

 

posted @ 2023-10-17 09:13  微笑的''80  阅读(131)  评论(0)    收藏  举报