本文介绍了警告C4018:'<' :签名/未签名不匹配ON VECTORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我在for循环中运行我的程序时,我收到一条警告,上面写着:



警告C4018:'<':签名/未签名不匹配





Hi,

when i run my program at the for loop i receive a warning which says:

warning C4018: '<' : signed/unsigned mismatch


void insertion_sort(vector<int> &items)
{
	cout<<" insertion_sort... ";
	int key = 0;
	int i=0;
	for( int j=2; j<items.size(); j++){//HERE
		key = items[j];
		i = j-1;
		while (i>0 && items[i]>key){
			items[i+1] = items[i];
			i=i-1;
		}
		items[i+1] = key;
	}
}





似乎我不能使用vector.size()。

将signed或unsigned int与vector.size()进行比较,vector.max_size()将不起作用。我甚至不能:





it seems like i cannot use vector.size() .
comparing a signed or unsigned int with a vector.size(), vector.max_size() won't work. i can't even:

cout<<items.size();
//or
cout<<items.max_size();
//or
signed int a = items.size();
cout<<a;
//or
unsigned int a = items.size();
cout<<a;
//or
int a = items.size();
cout<<a;











为什么会这样?

如何解决?

谢谢,






Why does it happen?
How can i fix it?
Thanks,

推荐答案


unsigned long i=0;
for(unsigned long j=2; j<items.size(); j++){


#pragma warning ( disable : 4018 )













or


void insertion_sort(vector<int> &items)
{
	cout<<" insertion_sort... ";
	int key = 0;
	int i=0;
	for( int j=2; j<(int)items.size(); j++){//HERE
		key = items[j];
		i = j-1;
		while (i>0 && items[i]>key){
			items[i+1] = items[i];
			i=i-1;
		}
		items[i+1] = key;
	}
}</int>


这篇关于警告C4018:'&lt;' :签名/未签名不匹配ON VECTORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:01