无法将向量<int>转换为 int* 用于布尔测试密码
Cannot convert vector<int> to int* for bool testPIN
对于类赋值,我不得不使用向量而不是数组重写此代码。我想我会使用现有的数组,并将它们指定为向量。但我得到了:
错误:无法将参数"1"的"std::vector"转换为"int*"'bool testPIN(int*,int*,int)'
我怎样才能避免这个错误?
#include <iostream>
#include<vector>
using namespace std;
// Function Prototype
bool testPIN(int [], int [], int);
int main ()
{
const int NUM_DIGITS = 7; // Number of digits in a PIN
int cpin1[NUM_DIGITS] = {2, 4, 1, 8, 7, 9, 0}; // Base set of values.
int cpin2[NUM_DIGITS] = {2, 4, 6, 8, 7, 9, 0};
int cpin3[NUM_DIGITS] = {1, 2, 3, 4, 5, 6, 7};
vector<int> pin1(cpin1, cpin1+7) ;
vector<int> pin2(cpin2, cpin2+7) ;
vector<int> pin3(cpin3, cpin3+7) ;
if (testPIN(pin1, pin2, NUM_DIGITS))
cout << "ERROR: pin1 and pin2 report to be the same.n";
else
cout << "SUCCESS: pin1 and pin2 are different.n";
if (testPIN(pin1, pin3, NUM_DIGITS))
cout << "ERROR: pin1 and pin3 report to be the same.n";
else
cout << "SUCCESS: pin1 and pin3 are different.n";
if (testPIN(pin1, pin1, NUM_DIGITS))
cout << "SUCCESS: pin1 and pin1 report to be the same.n";
else
cout << "ERROR: pin1 and pin1 report to be different.n";
return 0;
}
bool testPIN(int custPIN[], int databasePIN[], int size)
{................}
在这些情况下,阅读一篇好的参考文献会有所帮助。您需要获得vector
的底层数据数组:
testPIN(pin1.data(), pin2.data(), NUM_DIGITS))
如果您的实现不支持C++11,您可以执行以下操作:
testPIN(&pin1[0], &pin2[0], NUM_DIGITS))
但是,如果您被要求重新实现一些使用矢量的代码,您可能需要重新实现testPIN
函数:
bool testPIN(const std::vector<int>& custPIN1,
const std::vector<int>& custPIN2);
然后通过矢量:
testPIN(pin1, pin2);
testPIN(&pin1[0], &pin2[0], NUM_DIGITS)
因为CCD_ 3的内部存储器结构与CCD_。
请检查一下。
如何在C++中将矢量转换为数组
相关文章:
- 运算符 += 应用于 std::valarray<int*>
- C ++ txt 文件成数组逐行字符串和 int 用于纸牌游戏
- 使输出流式处理运算符适用于 boost::variant<std::vector<int>、int、double 的正确方法是什么>
- 为什么基于 int 的访问不适用于 std::get(std::tuple)?
- 正确语法,用于统一初始化名称中带有空格的类型的临时,如unsigned int
- 如何证明 -> 在 int* pMember = &(pSomeType->SomeIntMember) 时不用于顺从;
- 用于检查"is int"/"is double"/等的模板函数
- sqlite3 更改函数回调参数 void* not用于 int* C++
- 为什么现代C 仍然保留旧的C样式原型,用于int argc,char ** argv
- 是否有任何用于ConstexPR操作员 (INT)的应用程序(INT)
- 双指针 (int**) 和双括号,用于从 2D 数组中获取值
- OpenCL 的 clEnqueueReadBufferRect 适用于 int 但不适用于 double 数据类型
- 使用4用于循环的4矩阵上的数组下标的“ int [int]类型”
- 检测输入键的输入键,用于INT类型
- 无法获得 boost::spirit parser&lexer 适用于 std::string 或 int 或 double 以外的令牌类型
- map(long long int,long long int)不适用于key=1000 000 000(在long l
- Qt警告:正在传递用于转换QRect的qreal::QRect(int,int,int)
- 重载分辨率如何适用于 std::vector:<int>:insert
- C 不是运算符应用于 int
- 无法将向量<int>转换为 int* 用于布尔测试密码