美文网首页
字符变量和转义序列

字符变量和转义序列

作者: 波洛的汽车电子世界 | 来源:发表于2019-07-22 22:29 被阅读0次

字符变量

char
字符类型:位数 8位 bit
使用8个二进制表示一个char
空间:一个字节
取值范围:-128到127

七个一等于一后面七个零减一 1111111 (10000000-1) 2^7-1 )
wchar 宽字符类型
uchar 无符号

ASCII码

65 a
97A
32 空格
A - " " = a;

#include<cmath>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
  int num;
  char ch1, ch2, ch3;
  cout << "请输入一个数字:";
  cin >> num;
  //ch1 = cin.get();
  //ch2 = cin.get();
  //ch3 = cin.get();
  cin >> ch1 >> ch2 >> ch3;
  cout << num << "\t" << ch1 << "\t" << ch2 << "\t" << ch3 <<endl;

  return 0;
}

string

#include<cmath>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
 //string 是字符串类型
  string str = "你好!";
  cout << str << endl;

  return 0;
}

转义序列

#include<cmath>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
  //蜂鸣警报
  cout << "\a"<< "\a" << "\a"  << endl;

    return 0;
}

\n
\t
\a
'
"
?
\

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
  double attack1 = 272;
  double attack2 = 250;
  double attack3 = 240;


//右对齐
  cout << setw(8) <<attack1 <<
          setw(8) <<attack2 <<
          setw(8) <<attack3 <<endl;
//左对齐
cout <<left;
cout << setw(8) <<attack1 <<
        setw(8) <<attack2 <<
        setw(8) <<attack3 <<endl;
        //填充
cout << setfill('_'); //默认用空格来填充,这里用下划线
cout << setw(8) <<attack1 <<
        setw(8) <<attack2 <<
        setw(8) <<attack3 <<endl;


  return 0;
}

相关文章

  • 字符变量和转义序列

    字符变量 char字符类型:位数 8位 bit使用8个二进制表示一个char空间:一个字节取值范围:-128到12...

  • java初识

    java的数据类型 字面量 整数 浮点数 字符和字符串 boolean 空值 空值和空字符串的区别 转义序列 变量...

  • 转义字符

    转义序列 含义\ \ 字符' ' 字符" " 字符? ? 字符\a Alert 或 bell //...

  • 3.9 PHP字符串单引号和双引号的区别

    双引号中可以解析变量,而单引号中不能。 在双引号中可以用转移字符,单引号中转义字符\只能转义单引号,和转义转义字符...

  • python文本颜色设置

    1、语法:终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关,控制字符颜色的转义序列是...

  • PHP知识点

    字符串 在使用单引号字符串时,需要转义的只有反斜杠和单引号本身。 双引号字符转义序列: 如"\110"和"\x48...

  • perl语言再探之raku有记

    部分反斜线转义字符序列 转义序列描述\aASCII响铃字符\b退格\r回车\n换行\t制表符号\f换页\c[NAM...

  • 字符串及数据类型

    一. 定义方法 单引号 不能解析变量不能解析转义字符,只能解析单引号和反斜线本身变量和变量,变量和字符串,字符串和...

  • 正则表达式各种符号含义

    '\',转义字符 '^'和'$' '*','+'和'?',表示一个或一序列字符重复出现的次数 '{}',用以表示重...

  • 六、正则表达式的转义字符

    正则表达式中的反斜线(\)用来表示转义序列,或去掉元字符的转义。元字符包括:. * ? + ^ $ | \,所以需...

网友评论

      本文标题:字符变量和转义序列

      本文链接:https://www.haomeiwen.com/subject/twyglctx.html