本文介绍了关于向量的一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像这样的代码:

the code like this:

struct EdsSmsRefTable_t
{
	EdsSmsRefTable_t(DWORD dwRadioIssi)
	{
		dwIssi = dwRadioIssi;
	}
	DWORD	dwIssi;
};
int _tmain(int argc, _TCHAR* argv[])
{
	vector<EdsSmsRefTable_t> a;
        vector<EdsSmsRefTable_t> b;

	a.push_back(EdsSmsRefTable_t(10));
	vector<EdsSmsRefTable_t>::iterator begin = a.begin();

	if (begin == b.begin())
	{
		cout<<"=="<<endl;
	}
	cout<<"end"<<endl;
	getchar();
	return 0;
}


该代码在Visual Studio 2003中运行得很好,但是在Visual Studio 2005中运行时,Expression:vector迭代器不兼容.为什么?
错误: http://hi.csdn.net/space-1057418-do-album -picid-991700.html

感谢


the code runs very well in Visual Studio 2003,but runs fail in Visual Studio 2005 with Expression:vector iterators incompatible.why?
the error:http://hi.csdn.net/space-1057418-do-album-picid-991700.html

thanks

推荐答案


void Foo()
   std::vector<int> va;
   std::vector<int> vb;
   std::vector<int>::iterator it_va = va.begin();
   std::vector<int>::iterator va_end = va.end();
   if (it_va == va_end) // ok
      std::cout << "end of vector a" << std::endl;
   std::vector<int>::iterator it_vb = vb.begin();
   std::vector<int>::iterator vb_end = vb.end();
   if (it_vb == vb_end) // ok
      std::cout << "end of vector b" << std::endl;

   if (it_vb == va_end) // error!
      std::cout "something wonderful has happened ..." << std::endl;
}


        vector<edssmsreftable_t> a;
// Don't need this anymore, cannot compare iterators from two different containers
//        vector<edssmsreftable_t> b;

	a.push_back(EdsSmsRefTable_t(10));
	vector<edssmsreftable_t>::iterator begin = a.begin();

	if (begin == a.end())
        {
          // The iterator is the same as the end iterator.
          // That means you are at the end of the container.
          ...
        }
</edssmsreftable_t></edssmsreftable_t></edssmsreftable_t>



另外,如果您只是想检查容器是否为空,请使用stl容器的empty()成员函数.



Alternatively, if you just wanted to check if your container is empty, use the empty() member function of the stl container.


这篇关于关于向量的一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 04:39