void Verylong::normal() { for (auto i = lnum.begin(); i != lnum.back(); ++i) { if (abs(*i) >= base){ if (*i > 0) { if (i == lnum.back() - 1) lnum.push_back(*i / base); else *(i+1) += *i / base; *i %= base; } else{ if (i == lnum.back() - 1) lnum.push_back(*i / base); else *(i+1) += *i / base; *i = base + (*i % base); // т.к *i всегда отриц. а base всегда полож., эквивалентно *i = base - |i % base| } } } if (lnum[lnum.size() - 1] < 0){ lnum[lnum.size() - 1] *= -1; _sign = false; } else _sign = true; } 

gives an error on the line for (auto i = lnum.begin (); i! = lnum.back (); ++ i) what is the problem?

  • lnum this vector <int> - vlad4378

2 answers 2

 for (auto i = lnum.begin(); i != lnum.back(); ++i) 

i is of type std::vector<int>::iterator , while lnum.back() returns an object of type int . There is no != Operator that can compare int and std::vector<int>::iterator , which the compiler notifies you about.

When you work with iterators, then you need to use a begin()/end()(cbegin()/cend())

When you work with values, you can use a pair of front()/back()

But you need to understand that they exist for different purposes and can not be combined with each other directly.

    Why is there lnumb.back() I do not quite understand. In addition, this call on an empty container leads to undefined behavior. I can say nothing more.

     for(std::vector<T>::iterator it = lnumb.begin(); it != lnumb.end(); ++it) { /* std::cout << *it; ... */ } 
    • Yes, thank you all, confused back () and end () - vlad4378