這篇文章主要給大家介紹了關(guān)c語言find函數(shù)的使用方法,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用c語言find函數(shù)具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧。

c語言find函數(shù)的用法詳解
C語言之find()函數(shù)
find函數(shù)用于查找數(shù)組中的某一個指定元素的位置。
比如:有一個數(shù)組[0, 0, 5, 4, 4];
問:元素5的在什么位置,find函數(shù) 返回值 為 2;
find (數(shù)組名 + 起始查找元素的位置, 數(shù)組名 + 結(jié)束查找的元素位置, 想要查找的元素)
直接上代碼:
#include <iostream>
#include <vector>
#include <algorithm>//注意要包含該頭文件
using namespace std;
int main()
{
int nums[] = { 3, 1, 4, 1, 5, 9 };
int num_to_find = 5;
int start = 0;
int end = 5;
int* result = find( nums + start, nums + end, num_to_find );
if( result == nums + end )
{
cout<< "Did not find any number matching " << num_to_find << endl;
}
else
{
cout<< "Found a matching number: " << *result << endl;
}
return 0;
}關(guān)于c語言find函數(shù)的使用方法就分享到這里了,希望以上內(nèi)容可以對大家有一定的參考價值,可以學(xué)以致用。如果喜歡本篇文章,不妨把它分享出去讓更多的人看到。
網(wǎng)站名稱:c語言find函數(shù)的使用方法-創(chuàng)新互聯(lián)
標題網(wǎng)址:http://chinadenli.net/article6/gcsig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、自適應(yīng)網(wǎng)站、動態(tài)網(wǎng)站、外貿(mào)建站、定制開發(fā)、移動網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)