当前位置: 首页 > news >正文

string类详解(上)

文章目录

  • 目录
    • 1. STL简介
      • 1.1 什么是STL
      • 1.2 STL的版本
      • 1.3 STL的六大组件
    • 2. 为什么学习string类
    • 3. 标准库中的string类
      • 3.1 string类
      • 3.2 string类的常用接口说明

目录

  • STL简介
  • 为什么学习string类
  • 标准库中的string类
  • string类的模拟实现
  • 现代版写法的String类
  • 写时拷贝

1. STL简介

1.1 什么是STL

STL(standard template libaray-标准模板库):是C++标准库的重要组成部分,不仅是一个可复用的组件库,而且是一个包罗数据结构与算法的软件框架

1.2 STL的版本

  • 原始版本

Alexander Stepanov、Meng Lee 在惠普实验室完成的原始版本,本着开源精神,他们声明允许任何人任意运用、拷贝、修改、传播、商业使用这些代码,无需付费。唯一的条件就是也需要向原始版本一样做开源使用。HP 版本–所有STL实现版本的始祖。

  • P. J. 版本

由P. J. Plauger开发,继承自HP版本,被Windows Visual C++采用,不能公开或修改,缺陷:可读性比较低,符号命名比较怪异。

  • RW版本

由Rouge Wage公司开发,继承自HP版本,被C+ + Builder 采用,不能公开或修改,可读性一般。

  • SGI版本

由Silicon Graphics Computer Systems,Inc公司开发,继承自HP版本。被GCC(Linux)采用,可移植性好,可公开、修改甚至贩卖,从命名风格和编程风格上看,阅读性非常高。我们后面学习STL要阅读部分源代码,主要参考的就是这个版本

1.3 STL的六大组件

STL的六大组件

2. 为什么学习string类

C语言中,字符串是以’\0’结尾的一些字符的集合,为了操作方便,C标准库中提供了一些str系列的库函数,但是这些库函数与字符串是分离开的,不太符合OOP的思想,而且底层空间需要用户自己管理,稍不留神可能还会越界访问。

3. 标准库中的string类

3.1 string类

string类的具体信息可以通过cplusplus网站进行查阅

在使用string类时,必须包含#include头文件以及using namespace std;

3.2 string类的常用接口说明

我们先来总的看一下string类的常用接口:

  1. string类对象的常见构造
    string类对象的常见构造
  2. string类对象的容量操作
    string类对象的容量操作
  3. string类对象的访问及遍历操作
    string类对象的访问及遍历操作
  4. string类对象的修改操作
    string类对象的修改操作
  5. string类非成员函数
    string类非成员函数

接下来,我们通过一些具体的场景来学习如何使用这些接口:

  • 如何构造一个string类对象
    string类对象的构造
#include <iostream>
#include <string>using namespace std;void test_string1()
{//常用string s1;string s2("hello world");string s3(s2);//不常用 了解string s4(s2, 3, 5);string s5(s2, 3);string s6(s2, 3, 30);string s7("hello world", 5);string s8(10, 'x');cout << s1 << endl;cout << s2 << endl;cout << s3 << endl;cout << s4 << endl;cout << s5 << endl;cout << s6 << endl;cout << s7 << endl;cout << s8 << endl;cin >> s1;cout << s1 << endl;
}int main()
{test_string1();return 0;
}

补充:

void push_back(const string& s)
{}void test_string2()
{//构造string s1("hello world");//隐式类型转换string s2 = "hello world";const string& s3 = "hello world";push_back(s1);push_back("hello world");
}int main()
{test_string2();return 0;
}

  • string的遍历

第一种方法:

//class string
//{
//public:
//	//引用返回
//	//1. 减少拷贝
//	//2. 修改返回对象
//	char& operator[](size_t i)
//	{
//		assert(i < _size);
//
//		return _str[i];
//	}
//private:
//	char* _str;
//	size_t _size;
//	size_t _capacity;
//};void test_string3()
{string s1("hello world");cout << s1.size() << endl;//11//cout << s1.length() << endl;//11for (size_t i = 0; i < s1.size(); i++){s1[i]++;}s1[0] = 'x';//越界检查//s1[20];for (size_t i = 0; i < s1.size(); i++){//cout << s1.operator[](i) << " ";cout << s1[i] << " ";}cout << endl;const string s2("hello world");//不能修改//s2[0] = 'x';
}int main()
{test_string3();return 0;
}

size和operator[]
注: size() 与 length() 方法底层实现原理完全相同,引入 size() 的原因是为了与其他容器的接口保持一致,一般情况下基本都是用 size()

第二种方法:
iterator

void test_string4()
{string s1("hello world");//遍历方式2:迭代器string::iterator it1 = s1.begin();while (it1 != s1.end()){*it1 += 3;cout << *it1 << " ";++it1;}cout << endl;//cout << typeid(it1).name() << endl;
}int main()
{test_string4();return 0;
}

iterator的优势

void test_string4()
{list<int> lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);list<int>::iterator it = lt1.begin();while (it != lt1.end()){cout << *it << " ";++it;}cout << endl;
}int main()
{test_string4();return 0;
}

第三种方法:

void test_string4()
{string s1("hello world");//遍历方式3:范围for(通用的)//底层角度,它就是迭代器for (auto& e : s1){e++;//不会影响s1中的数据,它是一个赋值拷贝;要加上引用才会改变s1中的数据cout << e << " ";}cout << endl;cout << s1 << endl;list<int> lt1;lt1.push_back(1);lt1.push_back(2);lt1.push_back(3);for (auto& e : lt1){cout << e << " ";}cout << endl;
}int main()
{test_string4();return 0;
}

注: 除了普通迭代器之外,还有

  1. const迭代器
    const迭代器
void test_string5()
{const string s1("hello world");//string::const_iterator it1 = s1.begin();auto it1 = s1.begin();while (it1 != s1.end()){//不能修改//*it1 += 3;cout << *it1 << " ";++it1;}cout << endl;
}int main()
{test_string5();return 0;
}
  1. 反向迭代器
    反向迭代器
void test_string5()
{string s2("hello world");string::reverse_iterator it2 = s2.rbegin();//auto it2 = s2.rbegin();while (it2 != s2.rend()){*it2 += 3;cout << *it2 << " ";++it2;}cout << endl;const string s3("hello world");string::const_reverse_iterator it3 = s3.rbegin();//auto it3 = s3.rbegin();while (it3 != s3.rend()){//不能修改//*it3 += 3;cout << *it3 << " ";++it3;}cout << endl;
}int main()
{test_string5();return 0;
}

  • 按字典序排序
    排序
#include <algorithm>void test_string6()
{string s1("hello world");cout << s1 << endl;//s1按字典序(ASCII码)排序//sort(s1.begin(), s1.end());//第一个和最后一个不参与排序//sort(++s1.begin(), --s1.end());//前5个排序sort(s1.begin(), s1.begin() + 5);cout << s1 << endl;
}int main()
{test_string6();return 0;
}
  • 插入字符
    append
void test_string7()
{string s1("hello world");cout << s1 << endl;s1.push_back('x');cout << s1 << endl;s1.append(" yyyyyy!!");cout << s1 << endl;string s2("111111");s1 += 'y';s1 += "zzzzzzzz";s1 += s2;cout << s1 << endl;
}int main()
{test_string7();return 0;
}

注: 在string尾部追加字符时,s.push_back(‘c’) / s.append(1, ‘c’) / s += ‘c’ 三种的实现方式差不多,一般情况下string类的 += 操作用的比较多,+= 操作不仅可以连接单个字符,还可以连接字符串

  • 关于修改的一些接口
    insert
void test_string8()
{string s1("hello world");cout << s1 << endl;s1.assign("111111");cout << s1 << endl;//慎用,因为效率不高 -> O(N)//实践中需求也不高string s2("hello world");s2.insert(0, "xxxx");cout << s2 << endl;s2.insert(0, 1, 'y');cout << s2 << endl;s2.insert(s2.begin(), 'y');cout << s2 << endl;s2.insert(s2.begin(), s1.begin(), s1.end());cout << s2 << endl;
}int main()
{test_string8();return 0;
}
void test_string9()
{string s1("hello world");cout << s1 << endl;//erase效率不高,慎用,和insert类似,要挪动数据s1.erase(0, 1);cout << s1 << endl;//s1.erase(5);s1.erase(5, 100);cout << s1 << endl;//replace效率不高,慎用,和insert类似,要挪动数据string s2("hello world");s2.replace(5, 1, "%20");cout << s2 << endl;string s3("hello world hello bit");for (size_t i = 0; i < s3.size(); ){if (' ' == s3[i]){s3.replace(i, 1, "%20");i += 3;}else{i++;}}cout << s3 << endl;string s4("hello world hello bit");string s5;for (auto ch : s4){if (ch != ' '){s5 += ch;}else{s5 += "%20";}}cout << s5 << endl;
}int main()
{test_string9();return 0;
}

我们来做几个题目:

  • 仅仅反转字母
    仅仅反转字母
class Solution
{
public:bool isLetter(char ch){if (ch >= 'a' && ch <= 'z'){return true;}if (ch >= 'A' && ch <= 'Z'){return true;}return false;}string reverseOnlyLetters(string s){if (s.empty()){return s;}size_t begin = 0, end = s.size() - 1;while (begin < end){while (begin < end && !isLetter(s[begin])){++begin;}while (begin < end && !isLetter(s[end])){--end;}swap(s[begin], s[end]);++begin;--end;}return s;}
};
  • 字符串中的第一个唯一字符
    字符串中的第一个唯一字符
 class Solution
{
public:int firstUniqChar(string s){int count[26] = { 0 };//统计次数for (auto ch : s){count[ch - 'a']++;}for (size_t i = 0; i < s.size(); ++i){if (1 == count[s[i] - 'a']){return i;}}return -1;}
};
  • 验证回文串
    验证回文串
class Solution
{
public:bool isLetterOrNumber(char ch){return (ch >= '0' && ch <= '9')|| (ch >= 'a' && ch <= 'z');}bool isPalindrome(string s){for (auto& ch : s){if (ch >= 'A' && ch <= 'Z'){ch += 32;}}int begin = 0, end = s.size() - 1;while (begin < end){while (begin < end && !isLetterOrNumber(s[begin])){++begin;}while (begin < end && !isLetterOrNumber(s[end])){--end;}if (s[begin] != s[end]){return false;}else{++begin;--end;}}return true;}
};
  • 字符串相加
    字符串相加

法一:

//时间复杂度:O(N^2) 因为头插的效率太低
class Solution
{
public:string addStrings(string num1, string num2){int end1 = num1.size() - 1;int end2 = num2.size() - 1;string str;int next = 0;//进位while (end1 >= 0 || end2 >= 0){int x1 = end1 >= 0 ? num1[end1--] - '0': 0;int x2 = end2 >= 0 ? num2[end2--] - '0': 0;int x = x1 + x2 + next;//处理进位next = x / 10;x = x % 10;//头插//str.insert(0, 1, '0' + x);str.insert(str.begin(), '0' + x);}if (1 == next){str.insert(str.begin(), '1');}return str;}
};

法二:

//时间复杂度:O(N)
class Solution
{
public:string addStrings(string num1, string num2){int end1 = num1.size() - 1;int end2 = num2.size() - 1;string str;int next = 0;//进位while (end1 >= 0 || end2 >= 0){int x1 = end1 >= 0 ? num1[end1--] - '0': 0;int x2 = end2 >= 0 ? num2[end2--] - '0': 0;int x = x1 + x2 + next;//处理进位next = x / 10;x = x % 10;//尾插str += ('0' + x);}if (1 == next){str += '1';}reverse(str.begin(), str.end());return str;}
};

  • string类对象的容量操作
void TestPushBack()
{string s;size_t sz = s.capacity();cout << "capacity changed: " << sz << '\n';cout << "making s grow:\n";for (int i = 0; i < 200; ++i){s.push_back('c');if (sz != s.capacity()){sz = s.capacity();cout << "capacity changed: " << sz << '\n';}}
}void test_string10()
{string s1("hello world hello bit");cout << s1.size() << endl;cout << s1.capacity() << endl;cout << s1.max_size() << endl;TestPushBack();string s1("111111111");string s2("11111111111111111111111111111111111111111111111111");
}int main()
{test_string10();return 0;
}

string类在不同环境下的对比

void TestPushBack()
{string s;//知道需要多少空间,提前开好s.reserve(200);size_t sz = s.capacity();cout << "capacity changed: " << sz << '\n';cout << "making s grow:\n";for (int i = 0; i < 200; ++i){s.push_back('c');if (sz != s.capacity()){sz = s.capacity();cout << "capacity changed: " << sz << '\n';}}
}void test_string10()
{	TestPushBack();string s1("111111111");string s2("11111111111111111111111111111111111111111111111111");cout << s1.capacity() << endl;s1.reserve(100);cout << s1.capacity() << endl;s1.reserve(20);cout << s1.capacity() << endl;
}int main()
{test_string10();return 0;
}

reserve

void test_string11()
{string s1;//s1.resize(5, '0');s1.resize(5);s1[4] = '3';s1[3] = '4';s1[2] = '5';s1[1] = '6';s1[0] = '7';//76543//插入(空间不够会扩容)string s2("hello world");s2.resize(20, 'x');//删除s2.resize(5);//s2[10];try{s2.at(10);}catch (const exception& e){cout << e.what() << endl;}
}int main()
{test_string11();return 0;
}

注:

  1. clear()只是将string中有效字符清空,不改变底层空间大小。(代码中没有演示)
  2. resize(size_t n) 与 resize(size_t n, char c)都是将字符串中有效字符个数改变到n个,不同的是当字符个数增多时:resize(n)用0来填充多出的元素空间resize(size_t n, char c)用字符c来填充多出的元素空间。注意:resize在改变元素个数时,如果是将元素个数增多,可能会改变底层容量的大小,如果是将元素个数减少,底层空间总大小不变
  3. reserve(size_t res_arg=0):为string预留空间,不改变有效元素个数当reserve的参数小于string的底层空间总大小时,reserver不会改变容量大小
  4. 对string操作时,如果能够大概预估到放多少字符,可以先通过reserve把空间预留好。

  • string类的一些其他操作
#define _CRT_SECURE_NO_WARNINGS 1void test_string12()
{string file("test.cpp");FILE* fout = fopen(file.c_str(), "r");char ch = fgetc(fout);while (ch != EOF){cout << ch;ch = fgetc(fout);}
}int main()
{test_string12();return 0;
}
void test_string12()
{string file("string.cpp.zip");size_t pos = file.rfind('.');//string suffix = file.substr(pos, file.size() - pos);string suffix = file.substr(pos);cout << suffix << endl;
}int main()
{test_string12();return 0;
}
void test_string12()
{string url("https://gitee.com/ailiangshilove/cpp-class/blob/master/%E8%AF%BE%E4%BB%B6%E4%BB%A3%E7%A0%81/C++%E8%AF%BE%E4%BB%B6V6/string%E7%9A%84%E6%8E%A5%E5%8F%A3%E6%B5%8B%E8%AF%95%E5%8F%8A%E4%BD%BF%E7%94%A8/TestString.cpp");size_t pos1 = url.find(':');string url1 = url.substr(0, pos1 - 0);cout << url1 << endl;size_t pos2 = url.find('/', pos1 + 3);string url2 = url.substr(pos1 + 3, pos2 - (pos1 + 3));cout << url2 << endl;string url3 = url.substr(pos2 + 1);cout << url3 << endl;
}int main()
{test_string12();return 0;
}
void test_string13()
{string str("Please, replace the vowels in this sentence by asterisks.");size_t found = str.find_first_of("aeiou");while (found != string::npos){str[found] = '*';found = str.find_first_of("aeiou", found + 1);}cout << str << '\n';
}int main()
{test_string13();return 0;
}
void SplitFilename(const string& str)
{cout << "Splitting: " << str << '\n';size_t found = str.find_last_of("/\\");cout << " path: " << str.substr(0, found) << '\n';cout << " file: " << str.substr(found + 1) << '\n';
}int main()
{string str1("/usr/bin/man");string str2("c:\\windows\\winhelp.exe");SplitFilename(str1);SplitFilename(str2);return 0;
}
void test_string14()
{string s1 = "hello";string s2 = "world";string ret1 = s1 + s2;cout << ret1 << endl;string ret2 = s1 + "xxxxx";cout << ret2 << endl;string ret3 = "xxxxx" + s1;cout << ret3 << endl;//字典序比较cout << (s1 < s2) << endl;
}int main()
{test_string14();return 0;
}

一个题目:

  • 字符串最后一个单词的长度

字符串最后一个单词的长度

#include <iostream>
using namespace std;int main()
{string str;//默认规定空格或者换行是多个值之间分割//cin >> str;//获取一行中包含空格,不能用>>getline(cin, str);size_t pos = str.rfind(' ');cout << str.size() - (pos + 1) << endl;return 0;
}

  • 输入多行字符依次打印:
int main()
{//默认规定空格或者换行是多个值之间分割string str;//ctrl + z 就可以结束while (cin >> str){cout << str << endl;}return 0;
}
  • 字符串转整形,整形转字符串
int main()
{//atoi itoa//to_stringint x = 0, y = 0;cin >> x >> y;string str = to_string(x + y);cout << str << endl;int z = stoi(str);return 0;
}

相关文章:

string类详解(上)

文章目录 目录1. STL简介1.1 什么是STL1.2 STL的版本1.3 STL的六大组件 2. 为什么学习string类3. 标准库中的string类3.1 string类3.2 string类的常用接口说明 目录 STL简介为什么学习string类标准库中的string类string类的模拟实现现代版写法的String类写时拷贝 1. STL简介 …...

c# —— StringBuilder 类

StringBuilder 类是 C# 和其他一些基于 .NET Framework 的编程语言中的一个类&#xff0c;它位于 System.Text 命名空间下。StringBuilder 类表示一个可变的字符序列&#xff0c;它是为了提供一种比直接使用字符串连接操作更加高效的方式来构建或修改字符串。 与 C# 中的 stri…...

今日行情明日机会——20250217

2025年02月17日行情 后续投资机会分析 根据最新盘面信息&#xff0c;以下板块和个股具备潜在投资机会&#xff0c;需结合市场动态和基本面进一步验证&#xff1a; 1. 腾讯系AI&#xff08;18家涨停&#xff09; 核心逻辑&#xff1a;涨停家数最多&#xff08;18家&#xff0…...

Openshift或者K8S上部署xxl-job

本案例以版本2.3.0为例 1. 源码编译成jar包 source code: https://github.com/xuxueli/xxl-job/blob/2.3.0/ 这里我们会得到两个jar包&#xff1a;xxl-job-admin-2.3.0.jar和xxl-job-executor-sample-springboot-2.3.0.jar 2. 初始化mysql数据库 sql code: https://github.…...

vite+vue3开发uni-app时低版本浏览器不支持es6语法的问题排坑笔记

重要提示&#xff1a;请首先完整阅读完文章内容后再操作&#xff0c;以免不必要的时间浪费&#xff01;切记&#xff01;&#xff01;&#xff01;在使用vitevue3开发uni-app项目时&#xff0c;存在低版本浏览器不兼容es6语法的问题&#xff0c;如“?.” “??” 等。为了方便…...

使用 Apache PDFBox 提取 PDF 中的文本和图像

在许多应用中&#xff0c;我们需要从 PDF 文件中提取文本内容和嵌入的图像。为了实现这一目标&#xff0c;Apache PDFBox 是一个非常实用的开源工具库。它提供了丰富的 API&#xff0c;可以帮助我们轻松地读取 PDF 文件、提取其中的文本、图像以及其他资源。 本文将介绍如何使…...

centos7arm架构安装mysql服务

1.安装新版mysql前&#xff0c;需将系统自带的mariadb卸载 rpm -qa|grep mariadb //查找mariadb的rpm包 rpm -e mariadb-libs-5.5.56-2.el7.x86_64 //卸载mariadb包 2.去官网下载对应mysq包https://downloads.mysql.com/archives/community/ 3.解压下载包&…...

【个人开发】deepspeed+Llama-factory 本地数据多卡Lora微调

文章目录 1.背景2.微调方式2.1 关键环境版本信息2.2 步骤2.2.1 下载llama-factory2.2.2 准备数据集2.2.3 微调模式2.2.3.1 zero-3微调2.2.3.2 zero-2微调2.2.3.3 单卡Lora微调 2.3 踩坑经验2.3.1 问题一&#xff1a;ValueError: Undefined dataset xxxx in dataset_info.json.2…...

后端生成二维码,前端请求接口生成二维码并展示,且多个参数后边的参数没有正常传输问题处理

一、后端代码 1、controller GetMapping("/generateQRCode/{url}")ApiOperation(value "生成url链接二维码",notes "生成url链接二维码")public JsonResult<NewsQRCodeVo> generateQRCode(PathVariable String url,HttpServletRespons…...

NBT群落物种级丰度鉴定新方法sylph

文章目录 简介为什么选择Sylph&#xff1f;Sylph的工作原理 Install使用解析成gtdb格式sylph 能做什么&#xff1f;sylph 不能做什么&#xff1f;ANI定义如何使用 sylph-utils 生成包含分类信息的配置文件耗时&#xff1a;66个样本耗时1h 转成easymicroplot可用数据 简介 Sylp…...

长视频生成、尝试性检索、任务推理 | Big Model Weekly 第56期

点击蓝字 关注我们 AI TIME欢迎每一位AI爱好者的加入&#xff01; 01 COMAL:AConvergent Meta-Algorithm for Aligning LLMs with General Preferences 许多对齐方法&#xff0c;包括基于人类反馈的强化学习&#xff08;RLHF&#xff09;&#xff0c;依赖于布拉德利-特里&#…...

使用右侧值现象来处理一个word导入登记表的需求

需求也简单&#xff0c;导word文件用户登记表&#xff0c;有各部门的十几个版本&#xff08;为什么这么多&#xff1f;不知道&#xff09;。这里说下谈下我的一些代码做法&#xff1a; 需求分析&#xff1a; 如果能解决java字段和各项填的值怎么配对的问题&#xff0c;那么就…...

FRRouting配置与OSPF介绍,配置,命令,bfd算法:

文章目录 1、frrouting的配置&#xff1a;2、ospf2.1、检测和维护邻居关系2.2、ospfDR和BDR2.3、odpf邻居表2.4、ospf常用命令2.5、bfd配置 1、frrouting的配置&#xff1a; sudo service zebra start sudo service ospfd start telnet localhost 2604 en configure termina…...

基于ThinkPHP 5~8兼容的推荐算法类实现,

在现代推荐系统中&#xff0c;随着用户量和物品量的增长&#xff0c;传统的推荐算法可能会面临性能瓶颈。本文将介绍如何基于 ThinkPHP 实现一个高性能的推荐系统&#xff0c;结合显性反馈&#xff08;如兴趣选择&#xff09;、隐性反馈&#xff08;如观看时长、评论、点赞、搜…...

使用Python爬虫实时监控行业新闻案例

目录 背景环境准备请求网页数据解析网页数据定时任务综合代码使用代理IP提升稳定性运行截图与完整代码总结 在互联网时代&#xff0c;新闻的实时性和时效性变得尤为重要。很多行业、技术、商业等领域的新闻都可以为公司或者个人发展提供有价值的信息。如果你有一项需求是要实时…...

kong身份认证插件详解之Basic Auth插件

1.3、Basic Authentication 支持基于用户名和密码的基本认证&#xff0c;通常用于简单的身份验证场景。 1.3.1、环境准备 1.3.1.1、创建一个服务&#xff0c;basic-auth-service curl -i -s -X POST http://localhost:8001/services \--data namebasic-auth-service \--dat…...

Copilot基于企业PPT模板生成演示文稿

关于copilot创建PPT&#xff0c;咱们写过较多文章了&#xff1a; Copilot for PowerPoint通过文件创建PPT Copilot如何将word文稿一键转为PPT Copilot一键将PDF转为PPT&#xff0c;治好了我的精神内耗 测评Copilot和ChatGPT-4o从PDF创建PPT功能 Copilot for PPT全新功能&a…...

用React实现一个登录界面

使用React来创建一个简单的登录表单。以下是一个基本的React登录界面示例&#xff1a; 1. 设置React项目 如果你还没有一个React项目&#xff0c;你可以使用Create React App来创建一个。按照之前的步骤安装Create React App&#xff0c;然后创建一个新项目。 2. 创建登录组…...

前端布局的方式有哪些

前端布局的方式有哪些 在前端开发里&#xff0c;布局就像是装修房子&#xff0c;把不同的东西合理地摆放在合适的位置&#xff0c;让整个空间既美观又实用。下面给你介绍几种常见的前端布局方式&#xff1a; 1. 普通流布局&#xff08;标准文档流布局&#xff09; 这就像是按…...

seata集成nacos

#nacos集成nacos并配置mysql数据源 1. 所需依赖 <!--seata 分布式事务--><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-seata</artifactId></dependency> 2. 打开seata目录&#xff…...

第29篇 基于ARM A9处理器用C语言实现中断<五>

Q&#xff1a;怎样设计基于ARM A9处理器的C语言程序使用定时器中断实现实时时钟&#xff1f; A&#xff1a;在上一期的程序中添加A9 Private Timer作为第三个中断源&#xff0c;配置该定时器使其每隔0.01秒产生一次中断。使用该定时器使全局变量time的值递增&#xff0c;并将…...

deepseek多列数据对比,联想到excel的高级筛选功能

目录 1 业务背景 ​2 deepseek提示词输入 ​3 联想分析 4 EXCEL高级搜索 1 业务背景 系统上线的时候经常会遇到一个问题&#xff0c;系统导入的数据和线下的EXCEL数据是否一致&#xff0c;如果不一致&#xff0c;如何快速找到差异值&#xff0c;原来脑海第一反应就是使用公…...

C 程序多线程拆分文件

C 程序多线程拆分文件 在C语言中&#xff0c;实现多线程来拆分文件通常需要借助多线程库&#xff0c;比如 POSIX 线程库&#xff08;pthread&#xff09;或者 Windows 的线程库&#xff08;CreateThread 或类似的函数&#xff09;。下面我将分别展示在 Linux 和 Windows 环境下…...

mysql 使用 CONCAT、GROUP_CONCAT 嵌套查询出 json 格式数据

tb_factory表由 factory_code 和 factory_name 字段&#xff0c;查询出如下所示效果&#xff1a; {"factory_0001": "工厂1","factory_0002": "工厂2",... } select sql&#xff1a; SELECT CONCAT( "{",GROUP_CONCAT( C…...

Leetcode 2466. Count Ways To Build Good Strings

Problem Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following: Append the character ‘0’ zero times.Append the character ‘1’ one times. This can …...

分布式 IO 模块:食品罐装产线自动化与高效运行的推手

在当今竞争激烈的罐装视频生产行业&#xff0c;如何实现产线的自动化与连续性高效运行&#xff0c;成为了众多企业追求的核心目标。明达技术推出的MR30分布式 IO 模块作为一种先进的工业控制技术&#xff0c;正逐渐崭露头角&#xff0c;为食品罐装产线带来了前所未有的变革。 痛…...

rustdesk编译修改名字

最近&#xff0c;我用Rust重写了一个2W行C代码的linux内核模块。在此记录一点经验。我此前没写过内核模块&#xff0c;认识比较疏浅&#xff0c;有错误欢迎指正。 为什么要重写&#xff1f; 这个模块2W行代码量看起来不多&#xff0c;却在线上时常故障&#xff0c;永远改不完。…...

MySQL 窗口函数:功能、使用场景与性能优化

MySQL 8.0 引入了一个强大的新特性——**窗口函数&#xff08;Window Functions&#xff09;**。它为数据分析和复杂查询提供了极大的便利&#xff0c;但同时也可能带来性能问题。本文将带你快速了解窗口函数的功能、使用场景以及如何优化性能。 --- ## **什么是窗口函数&#…...

数据权限校验实践

数据权限控制实践 最近在实习中为公司项目完成一个文件数据权限校验代码的转换重构&#xff0c;写这篇博客来记录前后两种权限校验的实现方案与相关概念 原实现方案&#xff1a;RBAC-基于角色的访问控制 RBAC&#xff08;Role-Based Access Control&#xff09; RBAC 是一种常…...

spring boot对接clerk 实现用户信息获取

在现代Web应用中&#xff0c;用户身份验证和管理是一个关键的功能。Clerk是一个提供身份验证和用户管理的服务&#xff0c;可以帮助开发者快速集成这些功能。在本文中&#xff0c;我们将介绍如何使用Spring Boot对接Clerk&#xff0c;以实现用户信息的获取。 1.介绍 Clerk提供…...

公网远程家里局域网电脑过程详细记录,包含设置路由器。

由于从校内迁居小区,校内需要远程控制访问小区内个人电脑,于是早些时间刚好自己是电信宽带,可以申请公网ipv4不需要花钱,所以就打电话直接申请即可,申请成功后访问光猫设备管理界面192.168.1.1,输入用户名密码登录超管(密码是网上查下就有了)设置了光猫为桥接模式,然后…...

自制简单的图片查看器()

图片格式&#xff1a;支持常见的图片格式&#xff08;JPG、PNG、BMP、GIF&#xff09;。 import os import tkinter as tk from tkinter import filedialog, messagebox from PIL import Image, ImageTkclass ImageViewer:def __init__(self, root):self.root rootself.root.…...

25/2/17 <嵌入式笔记> 桌宠代码解析

这个寒假跟着做了一个开源的桌宠&#xff0c;我们来解析下代码&#xff0c;加深理解。 代码中有开源作者的名字。可以去B站搜着跟着做。 首先看下main代码 #include "stm32f10x.h" // Device header #include "Delay.h" #include &quo…...

Kafka偏移量管理全攻略:从基础概念到高级操作实战

#作者&#xff1a;猎人 文章目录 前言&#xff1a;概念剖析kafka的两种位移消费位移消息的位移位移的提交自动提交手动提交 1、使用--to-earliest重置消费组消费指定topic进度2、使用--to-offset重置消费offset3、使用--to-datetime策略指定时间重置offset4、使用--to-current…...

python中使用日期和时间差:datetime模块

datetime模块的表示时间的有 datetime.datetime #时间包含年月日时分秒毫秒 datetime.date #时间只包含年月日 datetime.time #只包含时分秒 获取当前时间 import datetime now datetime.datetime.now() print(now)得到 atetime中的年月日时分秒可以分别取出来 import da…...

申论对策建议类【2022江苏B卷第一题“如何开展网络直播”】

材料&#xff1a; 近年来&#xff0c;公安交管部门通过网络直播&#xff0c;将执法过程和执法细节以视频形式呈现在公众面前&#xff0c;吸引“围观”、组织点评&#xff0c;让执法过程变成一堂生动的法治公开课。 “各位网友&#xff0c;大家好&#xff01;这里是‘全国交通…...

Blazor-父子组件传递任意参数

在我们从父组件传参数给子组件时&#xff0c;可以通过子组件定义的[Parameter]特性的公开属性进行传值&#xff0c;但是当我们需要传递多个值的时候&#xff0c;就需要通过[Parameter]特性定义多个属性&#xff0c;有没有更简便的方式&#xff1f; 我们可以使用定义 IDictionar…...

Python的那些事第二十三篇:Express(Node.js)与 Python:一场跨语言的浪漫邂逅

摘要 在当今的编程世界里,Node.js 和 Python 像是两个性格迥异的超级英雄,一个以速度和灵活性著称,另一个则以强大和优雅闻名。本文将探讨如何通过 Express 框架将 Node.js 和 Python 结合起来,打造出一个高效、有趣的 Web 应用。我们将通过一系列幽默风趣的实例和表格,展…...

win11安装wsl报错:无法解析服务器的名称或地址(启用wsl2)

1. 启用wsl报错如下 # 查看可安装的 wsl --install wsl --list --online此原因是因为没有开启DNS的原因&#xff0c;所以需要我们手动开启DNS。 2. 按照如下配置即可 Google的DNS&#xff08;8.8.8.8和8.8.4.4) 全国通用DNS地址 (114.114.114.114) 3. 运行以下命令来重启 WSL…...

【设计模式】【结构型模式】桥接模式(Bridge)

&#x1f44b;hi&#xff0c;我不是一名外包公司的员工&#xff0c;也不会偷吃茶水间的零食&#xff0c;我的梦想是能写高端CRUD &#x1f525; 2025本人正在沉淀中… 博客更新速度 &#x1f44d; 欢迎点赞、收藏、关注&#xff0c;跟上我的更新节奏 &#x1f3b5; 当你的天空突…...

1997-2019年各省进出口总额数据

1997-2019年各省进出口总额数据 1、时间&#xff1a;1997-2020年 2、来源&#xff1a;国家统计局、各省年鉴 3、指标&#xff1a;进出口总额 4、范围&#xff1a;31省 5、指标解释&#xff1a;进出口总额‌是指以货币表示的一定时期内一国实际进出口商品的总金额&#xff…...

AI前端开发效率革命:拥抱AI,开启前端开发新纪元

前端开发行业竞争日益激烈&#xff0c;项目交付周期不断缩短&#xff0c;对开发效率的要求也越来越高。在这种高压环境下&#xff0c;开发者们常常面临着巨大的压力。而近年来&#xff0c;人工智能技术的飞速发展&#xff0c;特别是AI写代码工具的出现&#xff0c;为前端开发带…...

Rust编程语言入门教程(一)安装Rust

目录 引言一、为什么要用 Rust&#xff1f;二、与其他语言比较三、Rust 特别擅长的领域四、Rust 与 Firefox五、Rust 的用户和案例六、Rust 的优缺点七、安装 Rust1、访问官网下载 Rust2、下载完成&#xff0c;执行exe文件 八、Rust 安装验证九、开发工具结束语 引言 在当今快…...

Kubernetes控制平面组件:Kubernetes如何使用etcd

云原生学习路线导航页&#xff08;持续更新中&#xff09; kubernetes学习系列快捷链接 Kubernetes架构原则和对象设计&#xff08;一&#xff09;Kubernetes架构原则和对象设计&#xff08;二&#xff09;Kubernetes架构原则和对象设计&#xff08;三&#xff09;Kubernetes控…...

2025年-G4-Lc78--121. 买卖股票的最佳时机--(java版)

1.题目描述 2.思路 思路1: 做两轮排序&#xff0c;第一轮排序找到最小的那个数&#xff0c;然后再判断最小的那个数之后还有其他数吗&#xff0c;如果有在进行排序&#xff0c;选出最大的那个数&#xff0c;然后值相减。 问题要点&#xff1a; &#xff08;1&#xff09;你需要…...

LabVIEW 中的 3dgraph.llb 库

3dgraph.llb 库位于 C:\Program Files (x86)\National Instruments\LabVIEW 2019\vi.lib\Platform 目录下&#xff0c;是 LabVIEW 系统中用于 3D 图形相关操作的重要库。它为 LabVIEW 用户提供了丰富的功能&#xff0c;能在应用程序中创建、显示和交互各种 3D 图形&#xff0c;…...

通过VSCode直接连接使用 GPT的编程助手

GPT的编程助手在VSC上可以直接使用 选择相应的版本都可以正常使用。每个月可以使用40条&#xff0c;超过限制要付费。 如下图对应的4o和claude3.5等模型都可以使用。VSC直接连接即可。 配置步骤如下&#xff1a; 安装VSCODE 直接&#xff0c;官网下载就行 https://code.vis…...

[LeetCode力扣hot100]-C++常用数据结构

0.Vector 1.Set-常用滑动窗口 set<char> ans;//根据类型定义&#xff0c;像vector ans.count()//检查某个元素是否在set里&#xff0c;1在0不在 ans.insert();//插入元素 ans.erase()//删除某个指定元素 2.栈 3.树 树是一种特殊的数据结构&#xff0c;力扣二叉树相…...

2-安装YIUI

YIUI框架&#xff1a;GitHub - LiShengYang-yiyi/YIUI: Unity3D UGUI Framework, 基于UI数据事件绑定为核心 数据驱动的UGUI框架, ETUI框架, ET框架官方推荐UI框架 ET框架&#xff1a;egametang/ET: Unity3D Client And C# Server Framework (github.com) 1 - 安装YIUI框架&a…...

16-使用QtChart创建动态图表:入门指南

QtChart是Qt框架中的一个强大模块&#xff0c;用于创建各种类型的图表&#xff0c;如折线图、柱状图、饼图等。它提供了丰富的API和灵活的配置选项&#xff0c;使得开发者能够轻松地将数据可视化集成到应用程序中。本文将介绍如何使用QtChart创建一个简单的动态折线图&#xff…...