![]() |
|
#1
|
|||
|
|||
using vector push_back with iteratorhi all
i want to be able scan text moving from word to word with an iterator and which ever that word the iterator is on push it into a vector this is what i have but i get an error CPP / C++ / C Code:
Last edited by LuciWiz : 07-Feb-2005 at 00:09.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#2
|
||||
|
||||
|
Find a good STL reference, perhaps SGI's STL guide or this site. If you prefer a hard copy, I recommend getting your hands on "The ++ Standard Library," by Josuttis. It is important to understand the interface you plan to use before trying to use it in your own code.
If you are using g++, the error message you saw probably looked a lot like this. Quote:
It looks complicated, but learning to read and understand these compiler messages is extremely important when programming. This message says that you are passing the wrong type of argument to the method push_back. The push_back method on container vector takes an argument of type vector<_Tp>::value_type const&. Put simply, if you have a vector of strings, the method takes a string as its single argument, not an iterator that points to a string in your vector. The syntax for iterators is much like that for pointers. An iterator can be dereferenced to get the value, or object that is pointed to, like so: CPP / C++ / C Code:
Now, sorry to defer this to the end, but you have got two other problems here. First, you are starting position at the end of the vector, but you are using operator++ to increment it. CPP / C++ / C Code:
Second, you are modifying the vector with push_back while using the iterator, which essentially makes that iterator useless, or at least, unpredictable. Think about what it is that you are really trying to accomplish here. I'll be happy to help by answering specific questions if you have them. Matthew |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The