帶示例的 C++ STL 中的 array data()
陣列是相同資料型別的元素的集合,這些元素儲存在連續的記憶體位置中。
C++ 標準庫包含許多支援陣列執行的庫。其中之一是 array data() 方法。
array data() 在 c++ 中返回一個指向物件首個元素的指標。
語法
array_name.data();
引數
該函式不接受任何引數。
返回型別
指向陣列第一個元素的指標。
示例
闡述 Array 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
示例
闡述 Array 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP