13:枚举初步使用以及using名称空间

#include <iostream>
using namespace std;

//const int input = 0;
//const int output = 1;
//const int append = 2;

enum open_modes
{
input,
output,
append
};

//默认值从零递增
enum 打开模式
{
//input,
//output,
//append


输入模式,
输出模式,
追加模式
};

//值从 1 递增
enum forms
{
aa = 1,
bb, 
cc,
dd
};

int main()
{
double d;
//open_modes a;

打开模式 a;
d = 追加模式;
cout<<d<<endl;

///
system("pause");
return 0;

}

1,定义和初始化枚举

2,枚举成员是常量

3,每个enum都定义一种唯一的类型


///

#include <iostream>//标准头文件
#include <string>

//using namespace std;

//using std::cout;
using std::cin;
//using std::endl;
//using std::string;

int main()
{
//就像文件放在文件夹里:名称放在名称空间里
//::是作用域操作符,前面是名称空间
//cout名称    endl名称
std::cout<<"hello  名称空间"<<std::endl;

std::string s;
std::cout<<"请输入一个字符串:";
//std::cin>>s;
cin>>s;
std::cout<<"输入的是:"<<s<<std::endl;

//
std::cout<<"输入两个数:"<<std::endl;
int v1,v2;
cin>>v1>>v2;
std::cout<<v1<<" + "<<v2<<" = "<<v1+v2<<std::endl;

///
system("pause");
return 0;
}

1,每个名字都需要一个using 声明
2,头文件中:不能使用using 声明

如果需要使用,则写完整名称:std::cout



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值