What are the differences between list and vector? Thank you!
What are the differences between list and vector? Thank you!
One is usually spelt with 4 letters, and the other with 6 letters. For other differences, you could try reading SGI's Standard Template Library Programmer's Guide.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Depends on their implementations....
Generally Linked Lists are not contiguous in memory and thus require require linear access time in the worst case. Vectors can provide constant time access, but that depends on the implementation. Both are dynamically sized, but are used in different situations depending on the intented use.
Perhaps you could expand your question a little.
Originally Posted by laserlight
Man, how could I miss that! Back to the books for me....
By the way, why am i having a error here? And is it apropriate to use list or vector in this situation?
The error i get is: List Iterators incompatibleCode:list<string> Tokens; buf.erase((buf.length()-1), 1); Tokenize(buf, Tokens, "("); list<unsigned long int> Sizes; Tokens.pop_front(); /*list<string>::const_iterator it; for (;it != Tokens.end();it++) { Sizes.push_back(atoi((*it).c_str())); }*/ //REMOVED CONST ITERATOR -- NOT WORKING while (Tokens.size() > 0) { Sizes.push_back(atoi(Tokens.front().c_str())); Tokens.pop_front(); } int index = 0; // A MUST HAVE ITERATOR BUT NOT WORKING AS WELL for (list<unsigned long int>::const_iterator it;it != Sizes.end();it++) { buf = sock->ReceiveLine(); if (buf[0] == '.') break; Email EmailBuf; EmailBuf.ID = buf[0]; if (index == buf[0]) break; buf = "RETR "; buf += EmailBuf.ID; sock->SendLine(buf); sock->ReceiveLine(buf, (*it)); }
MS Visual C++ 2005, Windows XP Professional SP2
The only problem I see with that code is that you never assigned the variable "it" to Tokens.begin() or Sizes.begin(), which is necessary when you iterate. Fix that, then give both iterators meaningful and different names and see if it works and what the error is that you get if any.
You generally want to use vector by default. One reason to use list is if you are inserting and erasing in the middle of the container a lot, which you don't appear to be doing here. So I would use vector.
Thank you, i got some lack of attention, didn´t realized it was unassigned