日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

stl vector 函数_vector :: clear()函数,以及C ++ STL中的示例

發布時間:2025/3/11 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stl vector 函数_vector :: clear()函数,以及C ++ STL中的示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

stl vector 函數

C ++ vector :: clear()函數 (C++ vector::clear() function)

vector::clear() is a library function of "vector" header, it is used to remove/clear all elements of the vector, it makes the 0 sized vector after removing all elements.

vector :: clear()是“ vector”頭文件的庫函數,用于刪除/清除向量中的所有元素,刪除所有元素后將其大小設為0。

Note: To use vector, include <vector> header.

注意:要使用向量,請包含<vector>標頭。

Syntax of vector::clear() function

vector :: clear()函數的語法

vector::clear();

Parameter(s): none – It accepts nothing.

參數: 無 –不接受任何內容。

Return value: void – It returns nothing.

返回值: void –不返回任何內容。

Example:

例:

Input:vector<int> v1{ 10, 20, 30, 40, 50 };//clearing content of the vectorsv1.clear();cout <> v1.size();Output:0

C ++程序演示vector :: clear()函數的示例 (C++ program to demonstrate example of vector::clear() function)

//C++ STL program to demonstrate example of //vector::clear() function#include <iostream> #include <vector> using namespace std;int main() {//vector declarationvector<int> v1{ 10, 20, 30, 40, 50 };//printing elementscout << "before clearing the elements..." << endl;cout << "size of v1: " << v1.size() << endl;cout << "v1: ";for (int x : v1)cout << x << " ";cout << endl;//clearing all elementsv1.clear();//printing elementscout << "after clearing the elements..." << endl;cout << "size of v1: " << v1.size() << endl;cout << "v1: ";for (int x : v1)cout << x << " ";cout << endl;return 0; }

Output

輸出量

before clearing the elements... size of v1: 5 v1: 10 20 30 40 50 after clearing the elements... size of v1: 0 v1:

Reference: C++ vector::clear()

參考: C ++ vector :: clear()

翻譯自: https://www.includehelp.com/stl/vector-clear-function-with-example.aspx

stl vector 函數

總結

以上是生活随笔為你收集整理的stl vector 函数_vector :: clear()函数,以及C ++ STL中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。