C ++ STL中的数组data()及其示例
数组是存储在连续内存位置中的相同数据类型元素的集合。
C++标准库包含许多支持数组功能的库。其中之一是数组data()方法。
data()c++中的数组返回一个指向对象第一个元素的指针。
语法
array_name.data();
参数
该函数不接受任何参数。
返回类型
指向数组第一个元素的指针。
示例
程序来说明数组Data()方法的使用-
#include <bits/stdc++.h>
using namespace std;
int main(){
array<float, 4> percentage = { 45.2, 89.6, 99.1, 76.1 };
cout << "The array elements are: ";
for (auto it = percentage.begin(); it != percentage.end(); it++)
cout << *it << " ";
auto it = percentage.data();
cout << "\nThe first element is:" << *it;
return 0;
}输出结果
The array elements are: 45.2 89.6 99.1 76.1 The first element is:45.2
示例
演示如何使用数组Data()方法的程序
#include <bits/stdc++.h>
using namespace std;
int main(){
array<float, 4> percentage = { 45.2, 89.6, 99.1, 76.1 };
cout << "The array elements are: ";
for (auto it = percentage.begin(); it != percentage.end(); it++)
cout << *it << " ";
auto it = percentage.data();
it++;
cout << "\nThe second element is: " << *it;
it++;
cout << "\nThe third element is: " << *it;
return 0;
}输出结果
The array elements are: 45.2 89.6 99.1 76.1 The second element is: 89.6 The third element is: 99.1
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下