Jump to content
  • Advertisement
Sign in to follow this  
nuclear123

help with array of vectors iteration

This topic is 2537 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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!