*/
一、namespace演示
#include
#include
using namespace std;//使用命名空间 为了使用std中的cin cout endl等
//模拟ABC三个公司
namespace A
{
int x = 1;
void fun()
{
cout<<"A"< } } namespace B { int x = 2; void fun() { cout<<"B"< } void fun2() { cout<<"2B"< } } using namespace B;//下面的B中的fun2方法可以直接调用 int main() { cout<<"hello"< cout< B::fun();//在C公司中调用B公司的方法 fun2(); system("pause"); return 0; } 二、5-1综合练习 //判断求得的是最大值还是最小值 //如果最后的bool类型得到的是true,则得到的是最大值 //如果最后的bool类型得到的是false,则得到的是最小值 #include #include using namespace std; namespace CompA { int getMaxOrMin(int *arr,int count,bool isMax) { int temp = arr[0];//作为比较变量 for(int i = 1;i { if(isMax) { if(temp { temp = arr[i]; } } else { if(temp>arr[i]) { temp = arr[i]; } } } return temp; } } int main(void) { int arr1[4] = {3,5,1,7}; bool isMax = false; cin>>isMax; cout< system("pause");//不希望窗口瞬间结束 return 0; }



