I am currently trying to access specific value elements of my map and iterate through the map to print all of my map's keys with its specific elements but am running through errors when I am debugging on my IDE (Eclipse) Any ideas on how I can overcome this struggle? Been trying to find answer for the past few days.
when calling for std::find, it says,
'no matching member function for call to 'find'
when using iterator to iterator through map it says,
invalid operands to binary expression ('ostream' (aka 'basic_ostream') and 'const std::__1::vector >')
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <algorithm>
using namespace std;
int main() {
srand(time(NULL));
cout << "Enter # of rows: ";
int row;
cin >> row;
cout << "Enter # of columns: ";
int column;
cin >> column;
vector<vector<int> > numberBoard;
int startingIndex = 1;
for(int i = 0; i < row; i++){
vector<int> temp;
for(int j = 0; j < column; j++){
temp.push_back(startingIndex);
startingIndex++;
}
numberBoard.push_back(temp);
}
cout <<"Number Board:" << endl;
for(int i = 0; i < numberBoard.size(); i++){
for(int j = 0; j < numberBoard[i].size(); j++){
cout.width(5);
cout << numberBoard[i][j];
}
cout << endl;
}
vector<vector<char> > hiddenBoard(row, vector<char>(column));
// looping through outer vector vec
for (int i = 0; i < row; i++) {
// looping through inner vector vec[i]
for (int j = 0; j < column; j++) {
int random = rand()% 32 + 65;
(hiddenBoard[i])[j] = char(random);
//i*n + j;
}
}
cout << "\nBoard:" << endl;
for(int i = 0; i < hiddenBoard.size(); i++){
for(int j = 0; j < hiddenBoard[i].size(); j++){
cout.width(5);
cout << hiddenBoard[i][j];
}
cout << endl;
}
map<vector<int>, vector<char> > boardMap;
for(int i = 0; i < 20; i++){
boardMap[numberBoard[i]] = hiddenBoard[i];
}
//using std::find
int slotNum = 3;
map<vector<int>, vector<char> >::iterator it = boardMap.find(slotNum);
//trying to iterate through the map to print its corresponding key and value.
for(map<vector<int>, vector<char> >::iterator it = boardMap.begin(); it != boardMap.end(); it++){
cout << it->first << " => " << it->second << endl;
}
return 0;
}