一、问题描述
在使用using编译指令时,报错:Using directive refers to implicitly-defined namespace ‘std’。代码如下:
#include "Jack_N_Jill.h"
char fetch;
using namespace std; //报错
int main()
{
using Jill::fetch;
// double fetch;
// int fetch;
return 0;
}
二、错误原因
发生上述报错的原因是没有include头文件(比如iostream),导致编译器无法识别命名空间std.
三、解决方法
比如我需要使用std::cin函数,cin函数定义在iostream头文件中,那么引用这个头文件即可。下面是修改后的代码:
#include <iostream>
#include "Jack_N_Jill.h"
char fetch;
using namespace std;
int main()
{
using Jill::fetch;
// double fetch;
// int fetch;
cin >> fetch;
cin >> ::fetch;
return 0;
}