-1

I am learning stl features for the first time , so this code is from dietel and i wanted to implement in dev-c++ orwell 5.4 , but the code doesn't run , what is the problem . Are stl libraries not included in dev-cpp ?

And it is showing error - map doesnot name a type ?

#include <iostream>
#include <map>

typedef map< int , double , less< int > > Mid ; 
using namespace std ;

int main()
{
Mid pairs ;

pairs.insert( Mid::value_type( 15 , 2.7 ) ) ;
pairs.insert( Mid::value_type( 30 , 111.11 ) ) ;
pairs.insert( Mid::value_type( 5 , 1010.1 ) ) ;
pairs.insert( Mid::value_type( 10 , 22.22 ) ) ;
pairs.insert( Mid::value_type( 25 , 33.333 ) ) ;
pairs.insert( Mid::value_type( 5 , 77.54 ) ) ;
pairs.insert( Mid::value_type( 20 , 9.345 ) ) ;
pairs.insert( Mid::value_type( 15 , 99.3 ) ) ;

cout << "pairs contains:\nKey\tValue\n" ;

for( Mid::const_iterator iter = pairs.begin() ;
    iter != pairs.end() ; ++iter )
    cout << iter->first << '\t' << iter->second << '\n' ;

pairs[ 25 ] = 9999.99 ;
pairs[ 40 ] = 8765.43 ;
cout << endl ;
cout << "After subscript operations: " ;
cout << endl ;
for( Mid::const_iterator iter = pairs.begin() ;
    iter != pairs.end() ; ++iter )
    cout << iter->first << '\t' << iter->second << '\n' ;

cout << endl ;
return 0 ; 

}
banarun
  • 2,305
  • 2
  • 23
  • 40
abkds
  • 1,764
  • 7
  • 27
  • 43

2 Answers2

1

you are typedefing map before using namespace std;, that's why compiler can't see it

aryan
  • 621
  • 3
  • 10
1
#include <iostream>
#include <map>

typedef map< int , double , less< int > > Mid ; 
using namespace std ;

In this code snippet, you are using map before telling that you are using tht e namespace std. Therefore, your compiler does not know where to look for map and tells you it never heard about it. Just write:

using namespace std ;
typedef map< int , double , less< int > > Mid ;

It should fix that problem.

Morwenn
  • 21,684
  • 12
  • 93
  • 152