Cannot use .begin() or .end() on an array

后端 未结 6 1286
陌清茗
陌清茗 2020-12-05 10:01

The error reads:

request for member \'begin\', \'end\' in \'arr\' which is non class type int[5], unable to deduce from expression error.

6条回答
  •  眼角桃花
    2020-12-05 10:16

    For a standard fixed-length C array, you can just write

    int c_array[] = {1,3,5,7,9}, acc = 0;
    
    for (auto it : c_array) {
        acc += it;
    }
    

    The compiler does the behind-the-scenes work, eliminating the need to create all those begin and end iterators.

提交回复
热议问题