stl標準模板庫_C ++標準模板庫(STL)中的array :: fill()

stl標準模板庫

fill() is a member function of "array container", which sets a given value to all array elements. It can also be used to set the value to other of containers also. Value type should be same as container type.

fill()是“數組容器”的成員函數,它為所有數組元素設置一個給定值。 也可以將其設置為其他容器的值。 值類型應與容器類型相同。

For example – if an array is an integer type then provided value should be an integer type. If we provide other type of fill value, implicit cast type will be applied.

例如 –如果數組是整數類型,則提供的值應該是整數類型。 如果我們提供其他類型的填充值,則將應用隱式強制類型。

Syntax:

句法:

    arr_name.fill(value);

Program:

程序:

#include <iostream>
#include <array>
using namespace std;
int main() 
{
//declaring array with dynamic size
array<int,5> arr;
//print array elements with default values
cout<<"Array elements with default values:\n";
for (auto loop = arr.begin() ; loop != arr.end() ; ++loop)
cout<<*loop<<" ";
cout<<"\n";
//fill array element with 0
arr.fill (0);
//AGAIN...
//print array element with default values
cout<<"Array elements after filling with 0:\n";
for (auto loop = arr.begin() ; loop != arr.end() ; ++loop)
cout<<*loop<<" ";
cout<<"\n";
//fill array element with 0 
arr.fill (36);
//AGAIN...
//print array element with default values
cout<<"Array elements after filling with 36:\n";
for (auto loop = arr.begin() ; loop != arr.end() ; ++loop)
cout<<*loop<<" ";
cout<<"\n";
return 0;
}

Output

輸出量

Array elements with default values:
142 0 0 0 994036560 
Array elements after filling with 0:
0 0 0 0 0 
Array elements after filling with 36:
36 36 36 36 36 

Reference: C++ std::array::fill()

參考: C ++ std :: array :: fill()

翻譯自: https://www.includehelp.com/stl/array-fill-in-cpp-stl.aspx

stl標準模板庫

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378406.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378406.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378406.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Opencv——批量處理同一文件夾下的圖片(解決savedfilename = dest + filenames[i].substr(len)問題)

文章目錄前言一、完整代碼二、實現效果前言 第一份代碼實現了批量修改同一文件夾下圖片的尺寸&#xff0c;有其他需求時僅需修改處理部分的代碼以及文件夾路徑。 第二份代碼實現了批量截取同一文件夾下每張圖片的ROI區域作為結果保存&#xff0c;注意截取后按下enter鍵才會跳到…

linux統計文件目錄及其文件個數

linux下統計目錄及其子目錄的文件的個數 查看某目錄下文件的個數 ls -l |grep "^-"|wc -l或find ./company -type f | wc -l 查看某目錄下文件的個數&#xff0c;包括子目錄里的。 ls -lR|grep "^-"|wc -l查看某文件夾下目錄的個數&#xff0c;包括子目錄里…

處理文件、攝像頭和圖形用戶界面

1、基本I/O腳本 1.1 讀/寫圖像文件 import numpy import cv2#利用二維Numpy數組簡單創建一個黑色的正方形圖像 img numpy.zeros((3,3),dtypenumpy.uint8) img #結果為&#xff1a;array([[0, 0, 0],[0, 0, 0],[0, 0, 0]], dtypeuint8)img.shape#結果為&#xff1a;(3, 3)###…

linux桌面天氣,Ubuntu 14.10中安裝和配置天氣應用

對于操作系統平臺而言&#xff0c;有各種小插件功能方便用戶日常應用。在Ubuntu桌面中提供天氣信息的功能&#xff0c;可以使用Unity Dash和桌面應用來獲得相關信息&#xff0c;比如Typhoon。但對于用戶而言&#xff0c;可以提供快速查詢天氣狀況和溫度數據&#xff0c;并且只需…

使用ACE_SOCK_SEQPACK_Association獲取socket連接的本地及遠程IP端口信息

int connect(const std::string& ip, int port){ ACE_INET_Addr portAddr(port, ip.c_str()); ACE_SOCK_Connector connector; ACE_SOCK_Stream peer; if (-1 connector.connect(peer, portAddr)) { std::cout << "連接服務器(" <&…

linux批處理操作系統_批處理操作系統

linux批處理操作系統批處理操作系統 (Batch Processing Operating System) When we are working in an environment there is a restriction of making use of computer resources effectively and improvement in the programmers output. When we are working with tapes a l…

STL容器及其簡單應用(stack、priority_queue、vector、deuqe、list、map/multimap、set/multiset)

目錄前言【1】stack操作以及應用stack的幾個核心接口利用stack完成進制轉換【2】priority_queue操作以及應用priority_queue的幾個核心接口利用priority_queue完成合并果子問題【3】vector操作以及應用vector的幾個核心接口利用vector完成隨機排序【4】deuqe(雙向隊列)操作以及…

Android SAX API: XmlResourceParser及其擴展應用

XmlResourceParser繼承了2個接口&#xff1a;AttributeSet和XmlPullParser。其中XmlPullParser定義了Android SAX框架。跟Java 的SAX API相比&#xff0c;XmlPullParser令人難以置信地簡單。 一、使用XmlResourceParser讀取資源束中的xml 資源束是應用程序編譯后的應用程序包…

linux fdisk 磁盤空間使用率,linux查看磁盤剩余空間以及cpu使用情況

1、查看CPU個數cat /proc/cpuinfo | grep "physical id" | uniqtop可以實時的查看cpu的使用情況2、查看CPU核數cat /proc/cpuinfo | grep "cpu cores" | uniq3、查看CPU型號cat /proc/cpuinfo | grep model name |uniq4、查看內存cat /proc/meminfo | grep…

c語言 函數的參數傳遞示例_restder()函數,帶有C ++中的示例

c語言 函數的參數傳遞示例C restder()函數 (C remainder() function) remainder() function is a library function of cmath header, it is used to calculate the remainder (IEC 60559), it accepts two parameters (numerator and denominator) and returns the remainder…

jquery validation-jquery的驗證框架 詳解(1)

jquery validation驗證框架是一款非常優秀的客戶端數據驗證框架。我們在日常的項目中都會應用得到。今天開始我們會分兩到三個個階段 詳細的了解這款插件 至于這款插件是多么的優秀&#xff0c;怎么個描述法 我這里就不詳細述說。大家可以在接下來的時間里接觸并且感覺它的強大…

已知一個摻雜了多個數字字符的中文名拼音,去掉所有數字字符之后,形式為“名”+空格+“姓”;并且名和姓的首字母大寫,其他小寫,要求輸出姓名全拼,且全為小寫。(后附詳細樣例說明)

已知一個摻雜了多個數字字符的中文名拼音&#xff0c;去掉所有數字字符之后&#xff0c;形式為“名”空格“姓”&#xff1b;并且名和姓的首字母大寫&#xff0c;其他小寫&#xff0c;要求輸出姓名全拼&#xff0c;且全為小寫。&#xff08;后附詳細樣例說明&#xff09; 【輸入…

【視覺項目】【day2】8.21號實驗記錄(手機固定高度15cm拍攝+直方圖均衡化+模板匹配,模板12個,測試28個,效果十分差)

目錄均衡化代碼模板圖片按照大小排序總代碼測試效果新思路由于模板匹配是像素之間的比對&#xff0c;所以不同光照下的像素灰度值也會不同 所以在比對之前&#xff0c;我們需要對測試圖和模板圖進行直方圖均衡化&#xff0c;這一步可以先實現。 今天將采用批量處理的方式&#…

c語言 函數的參數傳遞示例_isgreater()函數以及C ++中的示例

c語言 函數的參數傳遞示例C isgreater()函數 (C isgreater() function) isgreater() function is a library function of cmath header, it is used to check whether the given first value is greater than the second value. It accepts two values (float, double or long…

在一個風景秀麗的小鎮,一天早上,有N名晨跑愛好者(編號1~N)沿著優雅的江邊景觀道朝同一方向進行晨跑

【問題描述】 在一個風景秀麗的小鎮&#xff0c;一天早上&#xff0c;有N名晨跑愛好者(編號1~N)沿著優雅的江邊景觀道朝同一方向進行晨跑&#xff0c;第i名跑者從位置si處起跑&#xff0c;且其速度為Vi。換句話說&#xff0c;對所有的實數t≥0&#xff0c;在時刻t時第i名跑者的…

linux內核測試,Linux內核測試的生命周期

內核持續集成(CKI)項目旨在防止錯誤進入 Linux 內核。在 Linux 內核的持續集成測試 一文中&#xff0c;我介紹了 內核持續集成Continuous Kernel Integration(CKI)項目及其使命&#xff1a;改變內核開發人員和維護人員的工作方式。本文深入探討了該項目的某些技術方面&#xff…

Linux下動態庫使用小結

1. 靜態庫和動態庫的基本概念 靜態庫&#xff0c;是在可執行程序連接時就已經加入到執行碼中&#xff0c;在物理上成為執行程序的一部分&#xff1b;使用靜態庫編譯的程序運行時無需該庫文件支持&#xff0c;哪里都可以用&#xff0c;但是生成的可執行文件較大。動態庫&#xf…

【視覺項目】【day3】8.22號實驗記錄(利用canny檢測之后的來進行模板匹配)

【day3】8.22號實驗記錄&#xff08;幾乎沒干正事的一天&#xff0c;利用canny檢測之后的來進行模板匹配&#xff09; 今天沒搞代碼&#xff0c;主要是問研究生學長工業攝像頭的接法的&#xff0c;學長也不知道&#xff0c;明天問問老師。。。 晚上搞了一下canny之后的模板匹配…

scala字符替換_如何替換Scala中的“壞”字符?

scala字符替換In Scala, programming language, all sorts of special characters are valid. The character set library is quite good and supports almost all characters in Scala programming. 在編程語言Scala中&#xff0c;各種特殊字符均有效。 字符集庫非常好&#x…

linux dd 大文件下載,Linux dd+grep 大文件二分查找

Linux dd 命令用于讀取、轉換并輸出數據。dd 可從標準輸入或文件中讀取數據&#xff0c;根據指定的格式來轉換數據&#xff0c;再輸出到文件、設備或標準輸出。參數說明(dd --help)Usage: dd [OPERAND]...or: dd OPTIONCopy a file, converting and formatting according to th…