[Solved] C++ reverse_iterator error


you should define your vector variable first :

std::vector<string> mylist (5);

then use a reverse_iterator for it :

std::vector<string>::reverse_iterator rit = mylist.rbegin();

update:

if you put using namespace std; then when you compile your code

you will find that the problem with list={}

because list is reserved class in namespace std so you can’t use it as variable name when you define vector.

to solve the problem you can simply give it another name like mylist.

Another way:

if you don’t put using namespace std;

no problem with declaring your vector as list

you can do it in this way and it will compile and work as you expected:

  std::vector<std::string> list={};
  std::vector<std::string>::reverse_iterator rit = list.rbegin(); 

I hope this will help you solve your error.

2

solved C++ reverse_iterator error