gpt4 book ai didi

c++ - 将 C++ 代码从 VS2003 迁移到 VS2010 后出现错误 C2678,错误 C2679 : binary '=' : no operator found which takes a right-hand operand of type 'int'

转载 作者:行者123 更新时间:2023-11-30 01:27:45 26 4
gpt4 key购买 nike

std::vector<std::string>::iterator it;

it = NULL;
do
{
if(it == NULL)
it = init.begin();
else
++it;
if(it == init.end())
return 1;
}
while(it->empty());

上面这段代码在VS2003上运行良好,但是当它迁移到VS2010时,它给出编译错误说

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
1> c:\program files\microsoft visual studio 10.0\vc\include\vector(388): could be 'std::_Vector_iterator<_Myvec> &std::_Vector_iterator<_Myvec>::operator =(const std::_Vector_iterator<_Myvec> &)'
1> with
1> [
1> _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1> ]
1> while trying to match the argument list '(std::_Vector_iterator<_Myvec>, int)'
1> with
1> [
1> _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1> ]
1>d:\vs2010_ws\acct ford 6.2.4 source code\acct_ford_ws\vector\src\driver\cancardxl.cpp(81): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::_Vector_iterator<_Myvec>' (or there is no acceptable conversion)
1> with
1> [
1> _Myvec=std::_Vector_val<std::string,std::allocator<std::string>>
1> ]

最佳答案

您假设可以从 int(或某种形式的指针?)初始化和分配 vector 迭代器。事实并非如此。

您可以将循环转换为类似以下内容:

if (init.empty())
return 1;

it = init.begin();
while (it->empty())
{
++it;
if (it == init.end())
return 1;
}

关于c++ - 将 C++ 代码从 VS2003 迁移到 VS2010 后出现错误 C2678,错误 C2679 : binary '=' : no operator found which takes a right-hand operand of type 'int' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8426671/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com