The array是存儲在連續內存位置的相同數據類型元素的集合。
C++ 標準庫包含許多支持數組函數的庫。其中之一是數組 data() 方法。
C++ 中的數組 data() 返回一個指向對象第一個元素的指針。
用法
array_name.data();
參數
該函數不接受任何參數。
返回類型
指向數組第一個元素的指針。
示例
Program To Illustrate The Use Of Array Data() Method −
#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
示例
Program To Illustrate The Use Of Array Data() Method
#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
相關用法
- C++ Array swap()用法及代碼示例
- C++ Array max_size()用法及代碼示例
- C++ Array get()用法及代碼示例
- C++ Array back()用法及代碼示例
- C++ Array empty()用法及代碼示例
- C++ Array tuple_size()用法及代碼示例
- C++ Array fill()用法及代碼示例
- C++ Array cbegin()用法及代碼示例
- C++ Array at()用法及代碼示例
- C++ Array cend()用法及代碼示例
- C++ Array end()用法及代碼示例
- C++ Array rbegin()用法及代碼示例
- C++ Array begin()用法及代碼示例
- C++ Array crend()用法及代碼示例
- C++ Array size()用法及代碼示例
- C++ Array rend()用法及代碼示例
- C++ Array front()用法及代碼示例
- C++ Array crbegin()用法及代碼示例
- C++ Algorithm copy()用法及代碼示例
- C++ Algorithm remove_if()用法及代碼示例
注:本文由純淨天空篩選整理自Sudhir sharma大神的英文原創作品 Array data() in C++ STL with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。