0

code:

#include<bits/stdc++.h>
using namespace std;
main()
{
    map<int, string>map1, map2;
    map1.insert(make_pair(1,"Sri Lanka"));
    map1.insert(make_pair(2,"India"));
    map1.insert(make_pair(3,"Bangladesh"));
    cout<<"Map1 size:"<<map1.size()<<endl;
    cout<<"Map2 size:"<<map2.size()<<endl;

    return 0;
}

Everytime I run map, error message will say.... enter image description here

What should I do?

  • `#include` -- Use the proper headers, not this one. Also, where is `int main()`? C++ is not C. – PaulMcKenzie Jun 06 '20 at 05:00
  • Perform a clean build to eliminate any stale garbage from previous builds that could be getting in your way. If that doesn't solve the problem you're doing something silly and not showing us. – user4581301 Jun 06 '20 at 06:39

1 Answers1

0

The main function requires a return type specified. The return type for main is int.

Second, the usage of <bits/stdc++.h> should be avoided, as it is not a standard header. Additional information found in this answer.

Here is what your program should look like to compile properly:

#include <map>
#include <string>
#include <iostream>

int main()
{
    std::map<int, std::string>map1, map2;
    map1.insert(std::make_pair(1,"Sri Lanka"));
    map1.insert(std::make_pair(2,"India"));
    map1.insert(std::make_pair(3,"Bangladesh"));
    std::cout << "Map1 size:" << map1.size() << std::endl;
    std::cout << "Map2 size:" << map2.size() << std::endl;
}
PaulMcKenzie
  • 34,698
  • 4
  • 24
  • 45