Why do c++ programmers use != instead of <

后端 未结 7 1925
天命终不由人
天命终不由人 2020-12-16 10:28

In c++ primer, pg 95 the author says that c++ programmers tend to use != in preference of < when writing loops.

for (vector::size_type i = 0;          


        
7条回答
  •  隐瞒了意图╮
    2020-12-16 11:05

    Because, in general, not all iterators support the "<" operation. See the manual for operation supported by each iterator type. Only random access iterators (of which, simple pointers are a subset) support inequality comparisons (< and >) between iterators

提交回复
热议问题