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

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

我正在尝试通过 g++ 编译器编译非常简单的 c++ 程序。

//main.cpp 

#include <stdio.h>

using namespace std;

typedef pair<int,int> pii;

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

但是我遇到了编译错误:“pair”没有命名类型

编译行:g++ main.cpp -o main.out OS: Ubuntu 16.04 升 g++: gcc 版本 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)

如果我只添加#include<iostrem>程序编译运行成功:)

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

using namespace std;

typedef pair<int,int> pii;

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

你知道吗,为什么会这样?

我的错,答案很简单:)

1) 对于使用 pair 我应该包括 <utility>.

2) <iostream> 某处包含 <utility>,这就是添加它后程序编译成功的原因:)