01_cout

cout

cout基本使用

# include <iostream> //< >包含系统头文件 input output straam

using namespace std; //使用命名空间std
cout << "Hello World!中文" << endl; //cout输出设备(终端,屏幕),endl换行
//不使用命名空间的话:
std::cout << "Hello World!中文" << std::endl; //很麻烦
//cout默认以十进制输出
cout << 0b001010 << endl; //10
cout << 0123 << endl; //83
cout << 0x58 << endl; //88

cout输出二进制数

//cout需要使用bitset<位数>(数值), 位数一般是8,16,32
#include<bitset>
cout << bitset<8>(0b001010) << endl; //00001010

cout输出八进制数

//cout需要使用oct输出八进制
cout << oct << 0123 << endl; //123

cout输出十六进制

//cout需要使用hex输出八进制
cout << hex << 0xab << endl; //ab

cout带变量输出

int a = 20;
cout << "a = " << a << endl; //a = 20

cout输出字符

cout << 'a' << endl; //a
cout << (int)'a' << endl; //97

cout看类型输出

posted @   爱吃冰激凌的黄某某  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
点击右上角即可分享
微信分享提示