Sign in to follow this  
nuclear123

help with array of vectors iteration

Recommended Posts

[code]

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()
{
}

};[/code]



[code]
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;
}[/code]


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 = [u][b]tk.ptrToRow[fileCount][/b][/u]->begin(); it != [b][u]tk.ptrToRow[fileCount][/u][/b]->end(); it++)
{
os << " [" << *it << "] ";
}
}

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
[quote name='nuclear123' timestamp='1318212063' post='4870927']the compiler is giving me an error[/quote]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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this