数据类型-转义字符和字符串型
1,数据类型-转义字符
2、数据类型-字符串型
- 转义字符
作用:用来表示一些ASCLL表中能不能显示的字符
#include <iostream>
using namespace std;
int main()
{
//常用的转义字符 举几个
//换行字符 — \n
cout << "hello \nworld!\n";
//输出反斜杠" \ " — "\\"
cout << "\\" << endl;
//水平制表符 — \t(一共占了八个空间,包含已经占了的字符) \t的作用:就是为了把后面的内容对其
cout << "ab\tefg" << endl; //e前面一共有八位
cout << "abc\tefg" << endl; //e前面一共有八位
cout << "abcefg\tefg" << endl; //e前面一共有八位
return 0;
}
运行结果:
字符串型。作用:用于表示一串字符串。
有两种字符串(我所学的),一种是C风格的字符串,另一种是C++风格的字符串。
//C风格字符串
#include <iostream>
using namespace std;
int main()
{
char arr1[] = "hello world!";
cout << arr1 << endl;
system("pause");
return 0;
}
//注意:1、要有[] 2、等号后也要有双引号: " "
- 运行结果:
//C++风格字符串
#include <iostream>
#include <string>
using namespace std;
int main()
{
string arr1 = "hello world!";
cout << arr1 << endl;
system("pause");
return 0;
}
- 运行结果: