转义字符均以反斜线开始,用于表示一些不能显示出来的ASCII字符,C++包括的转义字符有:
现阶段常用的有
\n 换行符
\ 反斜杠
\t 水平制表
示例:
#include <iostream>
using namespace std;
int main() {
//转义字符
//换行符 \n
cout << "hello world" << endl;
cout << "hello world\n";
//反斜杠 \\
//cout << "\" << endl; //无法输出短斜杠,报错
cout << "\\" << endl;
//水平制表符 \t
// \t占8个字符
cout << "aaaa\thelloworld" << endl;
cout << "aaa\thelloworld" << endl;
cout << "aaaaa\thelloworld" << endl;
}