I'm trying to switch from Turbo C++ to MSVC++, I've gotten most of the differences in coding and libraries worked out, though I keep getting this problem and I have tried to find a solution but I haven't been able to find one after 30 minutes of searching for it. I have various line of codes where I have for(I=0;I<Item.size();++I) , and in every single line I have that it gives me the warning.

warning C4018: '<' : signed/unsigned mismatch

Though since it is only a warning, it runs fine, but am I doing something wrong or do you do it a different way in Visual C++?

Recommended Answers

All 3 Replies

You must have declared I as an integer variable while size() returns a number of type unsigned integer. Hence the warning message. Try changing the loop variable to type size_t and it should work out to be fine.

Read this.

That works, thanks for the link and help!

comparing a signed value with an unsigned
value has a logical problem.

int si = -7 ;
unsigned int ui = 68 ;
( si < ui ) ; 
// true if interpreted as si < signed(ui)
// false if interpreted as unsigned(si) < ui

at the very least, the behavoiur is
'implementation dependant'

however, if the signed value is >= 0, and
the unsigned value is less than half of the
possible max value for the type, there
would be no differences between
implementations.

commented: Makes sense and helpful +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.