跳转到主要内容
Game Engine Sep 11, 2022 1 tags

使用标准库

使用标准库

cover

#include<iostream>
int maxin()
{
	std:count<<"Enter two numbers:"<<std::endl;
int v = 0, v2 = 0;
std::cin >> v1 >> v2;
std::count << "The sum of " << v1 << "and" << v2
					 << " is " << v1 + v2 << std::endl;
return 0;
}

细心的读者可能会注意到这个程序使用了std::cout和std::endl.而不是直接的cout和endl。前缀std::指出名字cout和endl是定义在名为std命名空间(namespace)中的。命名空间可以帮助我们避免不经意的名字定义冲突,以及使用库中相互同名字导致的冲突。标准库定义的所有名字都在命名空间std中。

通过命名空间使用标准库有一个副作用:当使用标准库中的一个名字时,必须显式说明我们想使用来自命名空间std中的名字。例如,而要写出std::cout,通过使用作用域运算符(::)来指出我们想使用定义在命名空间std中的名字cout。

Related Articles

继续阅读