小编Joe*_*Joe的帖子

如何将向量传递给函数?

我正在尝试将向量作为参数发送到函数,我无法弄清楚如何使其工作.尝试了一堆不同的方法,但他们都给出了不同的错误信息.我只包含部分代码,因为只有这部分不起作用.(向量"随机"填充了0到200之间的随机但排序的值)

更新了代码:

#include <iostream>     
#include <ctime>        
#include <algorithm>    
#include <vector>       

using namespace std;

int binarySearch(int first, int last, int search4, vector<int>& random);

int main()
{
    vector<int> random(100);

    int search4, found;
    int first = 0;
    int last = 99;

    found = binarySearch(first, last, search4, random);

    system("pause");    
    return(0);      
}

int binarySearch(int first, int last, int search4, vector<int>& random)
{
    do
    {
        int mid = (first + last) / 2;  
        if (search4 > random[mid]) 
            first = mid + 1;  
        else if (search4 < …
Run Code Online (Sandbox Code Playgroud)

c++ function vector

82
推荐指数
2
解决办法
25万
查看次数

标签 统计

c++ ×1

function ×1

vector ×1