How to extract an element from Vector

I try to extract the element in the for loop and I get an error.
Error C2440: 'initializing' : cannot convert from 'std::_Vector_const_iterator<_Myvec> *' to 'item'

Below is the code, it complain this particular line:-itemEntry it = &j; in the for loop
      typedef struct item
      {
            item(int n) : X(n) { }
            int X;
      }
        itemEntry;std::vector <itemEntry> itemList;
      std::vector<itemEntry>::const_iterator j;      
      itemEntry *it;
      it = new itemEntry(1);
      itemList.push_back (*it);
      it = new itemEntry(2);
      itemList.push_back (*it);

      for (j = itemList.begin(); j != itemList.end(); ++j)
            {
            itemEntry it = &j; // This causes an syntax error, I like to exract out and manipulate the content
            std::cout << j->X << std::endl;
            }


How do I correct this problem
tommym121Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
That seems to be a simple typo, that line has to be

itemEntry it = *j; // '*', not '&'

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tommym121Author Commented:
Thanks
0
peprCommented:
If there is any chance your compiler can or your project is allowed to use C++11 features, go for it. The new for loops and auto are a big enhancement, in my opinion. The loop would look like:
for (const auto &item: itemList)
{
    cout << item.X << endl;
}

Open in new window

0
evilrixSenior Software Engineer (Avast)Commented:
+1 for pepr's recommendation!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Laptops Notebooks

From novice to tech pro — start learning today.