c++复杂数据类型——数组,字符串
发布日期:2021-05-15 08:56:34 浏览次数:24 分类:精选文章

本文共 3741 字,大约阅读时间需要 12 分钟。

C++ ������������������������������

������

���������������������������������������������������������������������������������������������������������������������������������������

������������

long productIds[199];
productIds[0] = 20;
productIds[1] = 30;
productIds[2] = productIds[0] * productIds[1];

���������������������������������������������������������������������������������������������������������

int number[4] = {3, 6, 9, 12};  // ���������������
int productIds[4]; // ������������������������������0
float values[5] = {5.0, 2.1}; // ������������
float totals[200] = {}; // C++ 11+ ������������������������������������0

���������������C++ 11���������������������������������{}���������������������������������

���������������������

���������������������������������������������������������//������������������������������BETTER������������������

double c11_values1[4] {1.2, 3.3, 4.4, 5.5};  // ���������������
double c11_values2[] {1.2, 3.3, 4.4, 5.5}; // ������������

���������

������������������������������������������������������������������������������������������������������������������

1. C���������������������������������

char str1[6] = {'a', 'b', 'c', '\0', 'e', '\0'}; // ���������������
cout << str1; // ������ abc
cout << *(str1 +4); // ������'e'

������������������������������std::cin������������������

char name[20]; // ���������9���������������������
int size = 10;
cout << "���������������������������";
cin >> name;
cout << "���������������" << name << endl;

���������������������������������������������get������������������

2. ���������������

char str6[] = "abc" "def";  // ������������ abcdef
cout << "���������������" << str6 << endl;

���������������������������������������������pstr���

3. ���������������������

cout << strlen(str4) << endl; // ������������������������������������

���������������������������������������������������������strlen���������������std::string������������

4. ������������������������������

int n = strlen(str4);
for (int i=0; i

5. ������������������������������

������std::cin.get()���������������������������������������������������

char s[20];
cout << "������������������������";
cin >> s;
cout << "���������������" << s << endl;

���������������������������������������������������������������������������������

cin >> name;  // ���������������������������������������������
cin >> '\n'; // ���������������

������������std::getline������������������������������������std::string���������������������������

���������������

���������������

C++������������+=���������������������������������

string str = "abc";
str += "def"; // ������ str = "abcdef"

������C������������������������strcat���������������������������������������������

������������������������C���������������std::string������������������std::string::append������������������������C������������������strncat���������������������������

���������������������

int strLength = str.size();   // ���������������
int cStrLength = strlen(str); // ������������

���������������Raw String

���C++ 11������������������������������������������������������������������������������������

string unicodeStr = "������"; // UTF-8
char8 pinkStr[] = "���"; // UTF-16Code
char32_t high kariStr[] = L"������"; // ���������UTF-16���������������

Raw String

Raw������������������������������������������������������������������

cout << "Hello \nWorld" << endl;   // ���������Hello World
cout << R"(Hello \nWorld)" << endl; // ������������������

���������������String������Adjusting:

cout << R"((Hello \n (aa)\n \World))" // ������������������������������

���������������������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:c++复杂数据类型——结构体、共用体、枚举、匿名类型、类型别名
下一篇:c++ 中初始化、 自动类型转换、强制类型转换、auto关键字

发表评论

最新留言

关注你微信了!
[***.104.42.241]2025年04月09日 05时10分35秒