# Thread: List and Vector

1. ## List and Vector

What are the differences between list and vector? Thank you!

2. 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.

3. 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.

4. Originally Posted by laserlight
One is usually spelt with 4 letters, and the other with 6 letters.

Man, how could I miss that! Back to the books for me....

5. By the way, why am i having a error here? And is it apropriate to use list or vector in this situation?
Code:
```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));
}```
The error i get is: List Iterators incompatible
MS Visual C++ 2005, Windows XP Professional SP2

6. 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.

7. Thank you, i got some lack of attention, didn&#180;t realized it was unassigned

Popular pages Recent additions