954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

access element in a set of pairs

I am trying to print out a chess board on the console. The data structure i am using is a set of pairs. I am having trouble accessing the pair's elements. I do realize a map is probably better in this case but i am using somebody else's code so I don't want to mess with it. Thanks in advance!

error i am getting says: error: 'struct std::_Rb_tree_const_iterator' has no member named 'second'

Here is my code:

set< const pair<char, pair<int, int> >* > chosen;

for (int row=0; row<8; row++){
			for (int col=0; col<8; col++) {
				for (typename set<const A*>::iterator it = chosen.begin(); 
					 it != chosen.end(); it++) {
						if (*it->first=='B' 
							&& *it.second.first==row
							&& *it.second.second==col) {cout<<"B ";}
						else if (*it.first=='K' 
								 && *it.second.first==row
								 && *it.second.second==col) {cout<<"B ";}
						else {
								cout <<"_ ";
						}
					
					
				}
				cout <<"\n";
			}
		}
megatron21
Newbie Poster
3 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

I see *it->first , but later on you have *it.second ; they can't both be right. It's a set of pointers to pairs, try *it->second .

gusano79
Posting Pro
519 posts since May 2004
Reputation Points: 182
Solved Threads: 77
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: