下面编辑一个使用IO库的程序
#include<iostream>
int main()
{
std::cout << "Enter two numbers :" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2
<< " is " << v1 + v2 << std::endl;
return 0;
}
我们这里程序使用了std::cout以及std::cin、std::endl等,std前缀定义在名为std的命名空间中的,命名空间可以帮助我们不经意的名字定义冲突,标准库定义的所有名字都在命名空间std中。要是想使用来自命名空间中的名字就要加前缀std以及作用域运算符(::)若果想简化程序编写,可以在程序开头用using声明。
using namespace::name
using namespace::cout;
using namespace::cin;
using namespace::string;
这样就不用在程序编写过程中写前缀std;也可用最简洁的办法