c++17(1)-初始化列表,数字输出格式,for,auto

梦想与她 提交于 2020-01-31 22:34:19
#include <iostream>
using namespace  std ;
int main(int argc, char **argv)
{

    int nums[]  {1,2,3,4,5,6,7,8};
    int x{19};
    double y{3.8},z{9.08};
    string myStr1 {"hello"};
    char myStr2[]{"world"};
    for (char c:myStr1){
        cout<<c<<endl;
    }
    for (auto c:myStr1){
        cout<<c<<endl;
    }
    for (char c:myStr2){
        cout<<c<<endl;
    }    
    for(int x:nums){
        cout<<x+10<<endl;
    }
    cout<<x<<endl<<y<<endl<<z<<endl;
    cout<<"======"<<endl;
    cout<<"X"<<hex<<x<<endl;//十六进制
    cout<<dec<<x<<endl;//十进制
    cout<<"0"<<oct<<x<<endl;//八进制
     cout<<"======"<<endl;
    cout<<"X"<<hex<<x<<endl<<dec<<x<<endl<<"0"<<oct<<x<<endl;   
	return 0;
}
h
e
l
l
o
h
e
l
l
o
w
o
r
l
d

11
12
13
14
15
16
17
18
19
3.8
9.08
======
X13
19
023
======
X13
19
023
Hit any key to continue...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!