首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

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

2012-03-12 
请教一个关于std::与C库函数的问题#include stdio.hint main(){std::printf(world\n) //error!system

请教一个关于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

热点排行