help with array of vectors iteration

Started by
3 comments, last by JonBonazza 12 years, 6 months ago


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 << "] ";
}
}
Advertisement
will this work?
tk.ptrToRow[fileCount].begin();
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 ( -> ) ...

Eric Ranaldi a.k.a RanBlade


[size=1]"Passion is what drives you to stay up until 4am fixing that bug that hardly anyone would notice...


[size=1]Passion is where great games come from, if you dont live and breathe games you shouldn't be in the games industry."


[size=2]- Dave Pottinger, Ensemble Studios



[size=1][GameDev][C++ Page][Unity Game Engine][Panda3D Game Engine][NeHe Productions][Drunken Hyena][MSDN][Beej's Guide to Network Programming]


[size=1][FreedBSD][My Site][Gamasutra][Khan Acadamey]

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

Try this.


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



Co-founder/Lead Programmer
Bonafide Software, L.L.C.
Fairmont, WV 26554 US

This topic is closed to new replies.

Advertisement