-1
#include<stdio.h>
#include<map>

int main()
{
    int cases, i, j, act, answer, min_ind, min_val, temp1, temp2;
    scanf("%d",&cases);

    for(i=0; i<cases; i++)
    {
        answer = 0;
        scanf("%d", &act);
        map<int, int> mymap;

        for(j=0; j<act; j++)
        {
            scanf("%d",&temp1);
            scanf("%d",&temp2);
            mymap[temp2] = temp1;
        }

        map<int,int>::iterator it = mymap.begin();
        temp1 = it->second;

        while(mymap.size() != 0)
        {
            it = mymap.begin();
            if(it->second < temp1)
            {
                mymap.erase(it);
                continue;
            }

            answer++;
            temp1 = it->first;
            mymap.erase(mymap.begin());

            if(mymap.size() != 0)
            {
                it = mymap.begin();
                while(it->second < temp1)
                {
                    mymap.erase(it);
                    it = mymap.begin();
                }
            }
        }

        printf("%d\n",answer);
    }

    return 0;
}

I have included the map header as per the STL of C++ but still its not compiling and giving compilation error. I have tried including map.h header file but still getting the same error

Error:

prog.cpp: In function 'int main()':
prog.cpp:13: error: 'map' was not declared in this scope
prog.cpp:13: error: expected primary-expression before 'int'
prog.cpp:13: error: expected `;' before 'int'
prog.cpp:19: error: 'mymap' was not declared in this scope
prog.cpp:22: error: expected primary-expression before 'int'
prog.cpp:22: error: expected `;' before 'int'

Have a look at my code and help me out with this. Thanks for any help in advance.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Mcolorz
  • 145
  • 1
  • 5
  • 20

3 Answers3

6

You need to use the std namespace.

Either type std::map instead of map or use using std::map; at the beginning.

Or if you are really lazy, you can type using namespace std; to use all standard functions and types. But beware of name clashes.

user2345215
  • 637
  • 5
  • 9
2

It is in the std namespace, so you need to qualify it: std::map.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324
2

It's called std::map. You need to qualify the namespace.

You wouldn't have to do this if you'd written using namespace std; near the top of your program, which I actually don't recommend anyway.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055