• Advertisement
Sign in to follow this  

help with array of vectors iteration

This topic is 2328 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts



struct token
{
public:
string tokenName;
vector<int> ptrToRow[256];
int docID;
int cnt;

// Overloading operator
bool operator==(const token &tempToken)
{
return (this->tokenName == tempToken.tokenName);
}
friend ostream& operator<<(ostream& os, token& tk)
{
os << tk.tokenName << endl;
for(int j = 0; j < fileCount; j++)
{
os << "DocId: " << j+1 << endl;
for(vector<int>::iterator it = tk.ptrToRow->begin(); it != tk.ptrToRow->end(); it++)
{
os << " [" << *it << "] ";
}
}
return os;
}

token::token( int fileCount )
{
this->tokenName = "";
this->docID = 0;
this->cnt = 0;
}

token::~token()
{
}

};





friend ostream& operator<<(ostream& os, token& tk)
{
os << tk.tokenName << endl;
for(int j = 0; j < fileCount; j++)
{
os << "DocId: " << j+1 << endl;
for(vector<int>::iterator it = tk.ptrToRow->begin(); it != tk.ptrToRow->end(); it++)
{
os << " [" << *it << "] ";
}
}
return os;
}



so in the inner most for loop how to i tell it to move to the next element in the array? for example i want to do something similiar to this but the compiler is giving me an error


for(int j = 0; j < fileCount; j++)
{
os << "DocId: " << j+1 << endl;
for(vector<int>::iterator it = tk.ptrToRow[fileCount]->begin(); it != tk.ptrToRow[fileCount]->end(); it++)
{
os << " [" << *it << "] ";
}
}

Share this post


Link to post
Share on other sites
Advertisement
will this work?
tk.ptrToRow[fileCount].begin();

Share this post


Link to post
Share on other sites
in your example tk.ptrToRow[fileCount]->begin() ... would reference the same item each time as fileCount is the test you use to kill your for loop.... so it should be

tk.ptrToRow[j].begin() and .end() ...as stated above use the ( . ) operator not the ( -> ) ...

Share this post


Link to post
Share on other sites
the compiler is giving me an error
It's easier for us to help if you post the errors, but the above posts about [font="'Courier New"]->[/font] vs [font="'Courier New"].[/font] are probably what the errors are relating to...

Share this post


Link to post
Share on other sites

Try this.


for(vector<int>::iterator it = tk.ptrToRow[j].begin(); it != tk.ptrToRow[j].end(); it++)
{
os << " [" << *it << "] ";
}



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement