IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]win编程实践(2)【c++】

    u010255642发表于 2015-11-18 17:14:47
    love 0

    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;

    }      

     

    本博客所有内容是原创,如果转载请注明来源

    http://blog.csdn.net/myhaspl/

     

    结果如下:

     

    int

    int

    9 0   5   11  24



沪ICP备19023445号-2号
友情链接