When using deque in C++, the type when using auto

Asked 2 years ago, Updated 2 years ago, 130 views

How do I declare the same type of it in the for statement in the code below?

It doesn't come out properly even if I use typeid

My prediction is std::deque::iterator, is that right?

#include <iostream>
#include <deque>
#include <typeinfo>

using namespace std;

int main(){
      deque<int> dep;

      dep.push_back(10);


      int nSum=0;

      for(auto it = dep.begin(); it != dep.end(); it++){
            nSum += (*it);

            cout << typeid(it).name() << endl;
      }

      cout << nSum <<endl;

      return 0;
}

c++ stl c++11

2022-09-22 21:10

1 Answers

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.