win编程实践(2)【c++】
2015-11-18 17:14
393 查看
1、 auto让编译器自动确定类型,typeid返回类型,位移操作
源代码如下://ConsoleApplication1.cpp : 定义控制台应用程序的入口点。// #include "stdafx.h"#include <iostream> using std::cout;using std::endl;using std::cin; int main(){ //auto自动判断类型,typeid函数返回类型 int x = 5000; int y = 20; auto z1=x/y; auto z2=y/x; char temp; cout << typeid(z1).name()<< endl; cout << typeid(z2).name()<< endl; //位运算 int x1 = 0x0001; int x2 = 0x0008; int x3 = 0x0005; int x4 = 0x000A; int z3 = x1|x2;//或 int z4 = x1&x2;//与 int z5 = x1|x3;//或 int z6 = x1^x4;//异或 int z7 = x2 >> 2;//右移2位,除2^2 int z8 = z7 << 1;//左移1位,乘2 cout << z3<<" "<<z4<<" "<<z5<<" "<<z6<< " "<<z7<<" "<<z8<<endl; cin >> temp; return 0;}
结果如下:
int
int
9 0 5 11 24
源代码如下://ConsoleApplication1.cpp : 定义控制台应用程序的入口点。// #include "stdafx.h"#include <iostream> using std::cout;using std::endl;using std::cin; int main(){ //auto自动判断类型,typeid函数返回类型 int x = 5000; int y = 20; auto z1=x/y; auto z2=y/x; char temp; cout << typeid(z1).name()<< endl; cout << typeid(z2).name()<< endl; //位运算 int x1 = 0x0001; int x2 = 0x0008; int x3 = 0x0005; int x4 = 0x000A; int z3 = x1|x2;//或 int z4 = x1&x2;//与 int z5 = x1|x3;//或 int z6 = x1^x4;//异或 int z7 = x2 >> 2;//右移2位,除2^2 int z8 = z7 << 1;//左移1位,乘2 cout << z3<<" "<<z4<<" "<<z5<<" "<<z6<< " "<<z7<<" "<<z8<<endl; cin >> temp; return 0;}
本博客所有内容是原创,如果转载请注明来源
http://blog.csdn.net/myhaspl/
结果如下:
int
int
9 0 5 11 24
相关文章推荐
- c++ 设置console字体颜色
- C语言的按位与、或、非、异或 左移右移
- More Effective C++ 学习笔记(3)
- 像元纯度指数算法C++实现
- 给一列算术表达式解析,并找到最终结果
- C/C++中extern关键字详解
- C/C++中extern关键字详解
- c++封装多线程2
- C语言中EOF NULL NUL和'\0'的区别和使用
- C++中引用(&)的用法和应用实例
- 字符串数组反转输出 以空格为单词分隔符 C++
- C语言之const修饰符
- c++可变序列算法
- C语言文法
- 统计学习方法 --- 感知机模型原理及c++实现
- 在ubuntu下创建C++项目工程
- C/C++ 指针的使用
- Effective C++ 笔记
- C++拷贝构造函数详解
- C++ 显式调用DLL