
前言
大家好,我是yma16,本文分享csp题目中的分蛋糕题目。
c++ 处理字符串
C++中有多种方式处理字符串。
- C风格字符串
C风格字符串使用字符数组表示字符串,以空字符’\0’结尾。可以使用string.h头文件中的函数操作字符串。
示例代码:
#include <iostream>
#include <cstring> // 处理C风格字符串所需的头文件
using namespace std;
int main() {
char str[20];
strcpy(str, "hello"); // 复制字符串
cout << str << endl;
strcat(str, " world"); // 拼接两个字符串
cout << str << endl;
cout << strlen(str) << endl; // 获取字符串长度
if (strcmp(str, "hello world") == 0) {
cout &l