guest7 0 Junior Poster

Hi,

I am trying to read he has map starting from the second key instead of first key. I have two loops. One for loop iterator reads from the beginning of the has map. And the second for loop is trying to read from the second key of hash map. Following is my code. There is a compile time error at the colored portion in the code.

An example of what i am trying to do:

102
110

these are the two keys in my hash_map. I wish to combine these two keys to get a new key..so i have two for loops...first one to read the first key and the second one to read the second key. But it is not working.

#include <iostream>
#include <string>
#include <map>
#include <vector>
 
using namespace std;
typedef std::vector<int> v2;
 
int main()
{
        typedef map<v2,v2> mapType;
	mapType cube;
	v2 v1; 
     
       // let's declare some initial values to this map.
	v1.push_back(0);
	v1.push_back(1);
	v1.push_back(2);
	cout << cube.count(v1) << endl;
	if(cube.count(v1) <= 0)
	cube[v1].push_back(-2);
	cube[v1].push_back(3);
	cube[v1].push_back(-4);
	v1.clear();
	 
        v1.push_back(0);
	v1.push_back(1);
	v1.push_back(1);
	cout << cube.count(v1) << endl;
	if(cube.count(v1) <= 0)
	{
		cube[v1].push_back(-2);
		cube[v1].push_back(-3);
		cube[v1].push_back(-4);
	}
	v1.clear();
	
	for(mapType::const_iterator it = cube.begin(); it!= cube.end(); it++)
	{
		cout << "Key = ";
		for( vector<int>::const_iterator it1 = it->first.begin(); it1!= it->first.end(); it1++ )
		{
			cout << *it1 << " ";
		}
		cout << endl << "Value = ";
		for( vector<int>::const_iterator it2 = it->second.begin(); it2!= it->second.end(); it2++ )
		{
			cout << *it2 << " ";
		}
		cout << endl;
	}

	std::vector<int> tempo;

	// Try merging cubes here.
	for(mapType::const_iterator it = cube.begin(); it!= cube.end(); it++)
	{
		for(mapType::const_iterator its = cube.begin()+1; its!=
cube.end(); its++)
		{
			cout << "Key = ";
			vector<int>::const_iterator it1;
			vector<int>::const_iterator it3;
			for( it1 = it->first.begin(), it3 = its->first.begin(); it1!= it->first.end(), it3!= its->first.end(); it1++,it3++)
			{
				cout << *it1 << " " << *it3 << " ";
				if((*it1 == 0 && *it3 == 1) || (*it1 == 1 && *it3 == 0))
				break;
				else if(*it1 == *it3)
				tempo.push_back(*it1);
				else if((*it1 == 0 && *it3 == 2) || (*it1 == 2 && *it3 == 0))
				tempo.push_back(0);
				else 
				tempo.push_back(1);
			}
			cout << endl;
		}
	}
	
	for(int k=0; k<(int)tempo.size(); k++)
	{
		cout  << tempo[k] << " ";
	}

    return 0;
}

Any help is appreciated.