c++ - 将 vector 字符串传递给参数 vector 数组

标签 c++ vector

假设我创建了一个 vector 字符串 v 并将该 vector 传递给带有 vector 字符串数组的参数,我得到了一个编译器错误:没有匹配的调用函数。

我的函数

int functionA(vector <string> &a) //vector <string>  &a[] could not work
{}

在main中调用函数:

vector <string> a;
for(int i =0 ; i < a.size(); i++)
{
 functionA(a[i]); //Error at this line...
}

functionA(a) 应该有效,但我想在 vector 字符串中使用数组。我该怎么做?

最佳答案

如果你想通过

A) vectorstrings

调用:

vector <string> a;
..
..    
functionA(a); //notice this is not in for loop.

函数签名:

int functionA(vector <string> &a)

B) 仅字符串

调用:

for (unsigned int i=0; i < (unsigned int)a.size();i++)
   functionA(a.at(i));

函数签名:

int functionA(string &a)
{

关于c++ - 将 vector 字符串传递给参数 vector 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21472028/

相关文章:

c++ - std::vector.push_back() 抛出 badalloc 异常

c++ - 使用模板时如何使用 STL 容器的 size_type 类型?

c++ - 如何在 ROS2 的 create_subscription 方法中使用 std::bind 的 lambda intead

c++ - 将 vector 映射到特定范围

c++ - 小心 vector::reserve?

r - 从整数向量构建一个更长的向量,包括与原始整数的距离最多为 10 的所有整数

php openssl 签名字符串未通过 Win CryptoAPI 验证

C++:使用基类作为接口(interface)的实现

c++ - (编译器错误)为什么 C++ 找不到 .h 文件,即使它在那里?

c++ - 调整指针段错误的 vector