Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ compilation error: ‘pair’ does not name a type

I'm trying to compile very simple c++ program by g++ compiler.

//main.cpp 

#include <stdio.h>

using namespace std;

typedef pair<int,int> pii;

int main(int argc, char *argv[])
{
    printf("Hi");
    return 0;
}

But I'm getting compilation error: ‘pair’ does not name a type

Compile line: g++ main.cpp -o main.out OS: Ubuntu 16.04 lts g++: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)

If I just add #include<iostrem> program compiles and runs successfully:)

#include <stdio.h>
#include<iostream>

using namespace std;

typedef pair<int,int> pii;

int main(int argc, char *argv[])
{
    printf("Hi");
    return 0;
}

Do you know, why is this happens?

like image 739
Wsl_F Avatar asked Oct 16 '16 17:10

Wsl_F


1 Answers

My fault, answer is easy:)

1) For using pair I should include <utility>.

2) <iostream> somewhere includes <utility>, that's why after adding it program compiles successfully:)

like image 81
Wsl_F Avatar answered Oct 22 '22 13:10

Wsl_F