std命令空间问题,不包含strlen
问题描述:
#include<iostream>
#include<cstring>
int main()
{
std::cout<<std::strlen("puzzled")<<std::endl;
return 0;
}
编译器报错:'strlen' : is not a member of 'std'
但当导入整个命名空间后又可以(using namespace std)
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
cout<<strlen("puzzled")<<endl;
return 0;
}
1.什么原因呢,为什么使用std::strlen都无效呢?
2.另外想问一下,#include包含语句是怎样将C库的变量导入到std中的?
答
C++中的#include就等价于C中的#include
答
strlen是C库函数,C语言没有命名空间这种东西,自然不用加std::
答
C++中的#include就等价于C中的#include