读书人

请问一个关于std:与C库函数的有关问题

发布时间: 2012-03-12 12:45:32 作者: rapoo

请教一个关于std::与C库函数的问题
#include <stdio.h>

int main()
{
std::printf("world\n"); //error!
system("pause");
return 0;
}
编译结果:
printf is not a member of "std"

上述结果我清楚:C库函数没有用名字空间包裹

改为:
#include <iostream> //或<string>,<vector>,<map>,<list>,<set>均可编译通过
//但改为<limits>, <cctype>则不行
#include <stdio.h>

int main()
{
std::printf("world\n"); //error!
system("pause");
return 0;
}
不明白怎么回事,哪位帮忙指点一下??谢谢

[解决办法]
很简单,你只包含stdio.h,是没有引入std里的任何东西的,所以也没有 std::printf
而你包含了iostream,在有些系统中,他会隐含的包含cstdio,所以也就有了 std::printf

读书人网 >C++

热点推荐