当前位置: 首页 > 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简介 …...

Visual Studio Code使用ai大模型编成

1、在Visual Studio Code搜索安装roo code 2、去https://openrouter.ai/settings/keys官网申请个免费的配置使用...

外贸跨境订货系统流程设计、功能列表及源码输出

在全球化的商业环境下&#xff0c;外贸跨境订货系统对于企业拓展国际市场、提升运营效率至关重要。该系统旨在为外贸企业提供一个便捷、高效、安全的订货平台&#xff0c;实现商品展示、订单管理、物流跟踪等功能&#xff0c;满足跨境业务的多样化需求。以下将详细阐述外贸订货…...

TraeAi上手体验

一、Trae介绍 由于MarsCode 在国内由于规定限制&#xff0c;无法使用 Claude 3.5 Sonnet 模型&#xff0c;字节跳动选择在海外推出 Trae&#xff0c;官网&#xff1a;https://www.trae.ai/。 二、安装 1.下载安装Trae-Setup-x64.exe 2.注册登录 安装完成后&#xff0c;点击登…...

深入解析 vLLM:高性能 LLM 服务框架的架构之美(一)原理与解析

修改内容时间2.4.1处理请求的流程&#xff0c;引用更好的流程图2025.02.11首发2025.02.08 深入解析 vLLM&#xff1a;高性能 LLM 服务框架的架构之美&#xff08;一&#xff09;原理与解析 深入解析 vLLM&#xff1a;高性能 LLM 服务框架的架构之美&#xff08;二&#xff09;…...

thingboard告警信息格式美化

原始报警json内容&#xff1a; { "severity": "CRITICAL","acknowledged": false,"cleared": false,"assigneeId": null,"startTs": 1739801102349,"endTs": 1739801102349,"ackTs": 0,&quo…...

redis解决高并发看门狗策略

当一个业务执行时间超过自己设定的锁释放时间&#xff0c;那么会导致有其他线程进入&#xff0c;从而抢到同一个票,所有需要使用看门狗策略&#xff0c;其实就是开一个守护线程&#xff0c;让守护线程去监控key&#xff0c;如果到时间了还未结束&#xff0c;就会将这个key重新s…...

Python函数的函数名250217

函数名其实就是一个变量&#xff0c;这个变量就是代指函数而已函数也可以被哈希&#xff0c;所以函数名也可以当作集合中的元素&#xff0c;也可作为字典的key值 # 将函数作为字典中的值&#xff0c;可以避免写大量的if...else语句 def fun1():return 123 def fun2():return 4…...

Unity 获取独立显卡数量

获取独立显卡数量 导入插件包打开Demo 运行看控制台日志 public class GetGraphicCountDemo : MonoBehaviour{public int count;// Start is called before the first frame updatevoid Start(){count this.GetIndependentGraphicsDeviceCount();}}...

JAVA生产环境(IDEA)排查死锁

使用 IntelliJ IDEA 排查死锁 IntelliJ IDEA 提供了强大的工具来帮助开发者排查死锁问题。以下是具体的排查步骤&#xff1a; 1. 编写并运行代码 首先&#xff0c;我们编写一个可能导致死锁的示例代码&#xff1a; public class DeadlockExample {private static final Obj…...

如何正确安装Stable Diffusion Web UI以及对应的xFormers

本文是我总结的步骤&#xff0c;验证了几次保证是对的。因为正确的安装 Stable Diffusion Web UI 以及对应的 xFormers 实在是太麻烦了&#xff0c;官方和网上的步骤都是残缺和分散的&#xff0c;加上国内网络速度不理想&#xff0c;所以需要一些额外步骤&#xff0c;之前研究出…...

机器学习_14 随机森林知识点总结

随机森林&#xff08;Random Forest&#xff09;是一种强大的集成学习算法&#xff0c;广泛应用于分类和回归任务。它通过构建多棵决策树并综合它们的预测结果&#xff0c;显著提高了模型的稳定性和准确性。今天&#xff0c;我们就来深入探讨随机森林的原理、实现和应用。 一、…...

机器学习基本篇

文章目录 1 基本概念2 基本流程2.0 数据获取2.1 预处理2.1.0 认识数据认识问题2.1.1 不平衡标签的处理a.随机过采样方法 ROS,random over-samplingb. SMOTE synthetic minority Over-Sampling Technique2.2 缺失值处理2.3 数据清洗2.3.0离散特征编码2.3.1 连续特征处理归一化标…...

vue2.x与vue3.x生命周期的比较

vue2.x 生命周期图示&#xff1a; new Vue() | v Init Events & Lifecycle | v beforeCreate | v created | v beforeMount | v mounted | v beforeUpdate (when data changes) | v updated | v beforeDestroy (when vm.…...

接口测试及常用接口测试工具(Postman/Jmeter)

&#x1f345; 点击文末小卡片 &#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快 首先&#xff0c;什么是接口呢&#xff1f; 接口一般来说有两种&#xff0c;一种是程序内部的接口&#xff0c;一种是系统对外的接口。 系统对外的接口&#xf…...

[论文阅读] SeeSR: Towards Semantics-Aware Real-World Image Super-Resolution

文章目录 一、前言二、主要贡献三、Introduction四、Methodology4.1 Motivation &#xff1a;4.2Framework Overview.** 一、前言 通信作者是香港理工大学 & OPPO研究所的张磊教授&#xff0c;也是图像超分ISR的一个大牛了。 论文如下 SeeSR: Towards Semantics-Aware Rea…...

Python实战进阶 No1: RESTful API - 基于Flask的实例说明

Python实战进阶 No1: RESTful API - 基于Flask的实例说明 RESTful API 是一种基于 REST&#xff08;Representational State Transfer&#xff09; 架构风格的 Web 服务接口设计规范。它使用 HTTP 协议的标准方法&#xff08;如 GET、POST、PUT、DELETE 等&#xff09;来操作资…...

Redis——优惠券秒杀问题(分布式id、一人多单超卖、乐悲锁、CAS、分布式锁、Redisson)

#想cry 好想cry 目录 1 全局唯一id 1.1 自增ID存在的问题 1.2 分布式ID的需求 1.3 分布式ID的实现方式 1.4 自定义分布式ID生成器&#xff08;示例&#xff09; 1.5 总结 2 优惠券秒杀接口实现 3 单体系统下一人多单超卖问题及解决方案 3.1 问题背景 3.2 超卖问题的…...

OpenCV机器学习(5)逻辑回归算法cv::ml::LogisticRegression

OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 cv::ml::LogisticRegression 是 OpenCV 机器学习模块中的一个类&#xff0c;用于实现逻辑回归算法。逻辑回归是一种广泛应用于分类问题的统计方法&#xff0c;特别适合二分类任务。…...

百度百舸 DeepSeek 一体机发布,支持昆仑芯 P800 单机 8 卡满血版开箱即用

在私有云环境中成功部署 DeepSeek 满血版并实现性能调优&#xff0c;并不是一件容易的事情。选择合适的 GPU 配置、安装相应的环境、成功部署上线业务、加速推理任务加速、支撑多用户并发 …… 完成业务测试&#xff0c;成功融入生产业务中。 为了帮助企业快速实现 DeepSeek 服…...

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…...

IGP(Interior Gateway Protocol,内部网关协议)

IGP&#xff08;Interior Gateway Protocol&#xff0c;内部网关协议&#xff09; 是一种用于在一个自治系统&#xff08;AS&#xff09;内部传递路由信息的路由协议&#xff0c;主要用于在一个组织或机构的内部网络中决定数据包的最佳路径。与用于自治系统之间通信的 EGP&…...

STM32+rt-thread判断是否联网

一、根据NETDEV_FLAG_INTERNET_UP位判断 static bool is_conncected(void) {struct netdev *dev RT_NULL;dev netdev_get_first_by_flags(NETDEV_FLAG_INTERNET_UP);if (dev RT_NULL){printf("wait netdev internet up...");return false;}else{printf("loc…...

大语言模型如何处理长文本?常用文本分割技术详解

为什么需要文本分割? 引言:为什么需要文本分割?一、基础文本分割方法1. 按段落分割(Paragraph Splitting)2. 按句子分割(Sentence Splitting)二、高级文本分割策略3. 重叠分割(Sliding Window)4. 递归分割(Recursive Splitting)三、生产级工具推荐5. 使用LangChain的…...

屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!

5月28日&#xff0c;中天合创屋面分布式光伏发电项目顺利并网发电&#xff0c;该项目位于内蒙古自治区鄂尔多斯市乌审旗&#xff0c;项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站&#xff0c;总装机容量为9.96MWp。 项目投运后&#xff0c;每年可节约标煤3670…...

RabbitMQ入门4.1.0版本(基于java、SpringBoot操作)

RabbitMQ 一、RabbitMQ概述 RabbitMQ RabbitMQ最初由LShift和CohesiveFT于2007年开发&#xff0c;后来由Pivotal Software Inc.&#xff08;现为VMware子公司&#xff09;接管。RabbitMQ 是一个开源的消息代理和队列服务器&#xff0c;用 Erlang 语言编写。广泛应用于各种分布…...

三分算法与DeepSeek辅助证明是单峰函数

前置 单峰函数有唯一的最大值&#xff0c;最大值左侧的数值严格单调递增&#xff0c;最大值右侧的数值严格单调递减。 单谷函数有唯一的最小值&#xff0c;最小值左侧的数值严格单调递减&#xff0c;最小值右侧的数值严格单调递增。 三分的本质 三分和二分一样都是通过不断缩…...

Git 3天2K星标:Datawhale 的 Happy-LLM 项目介绍(附教程)

引言 在人工智能飞速发展的今天&#xff0c;大语言模型&#xff08;Large Language Models, LLMs&#xff09;已成为技术领域的焦点。从智能写作到代码生成&#xff0c;LLM 的应用场景不断扩展&#xff0c;深刻改变了我们的工作和生活方式。然而&#xff0c;理解这些模型的内部…...

tomcat指定使用的jdk版本

说明 有时候需要对tomcat配置指定的jdk版本号&#xff0c;此时&#xff0c;我们可以通过以下方式进行配置 设置方式 找到tomcat的bin目录中的setclasspath.bat。如果是linux系统则是setclasspath.sh set JAVA_HOMEC:\Program Files\Java\jdk8 set JRE_HOMEC:\Program Files…...

【Linux手册】探秘系统世界:从用户交互到硬件底层的全链路工作之旅

目录 前言 操作系统与驱动程序 是什么&#xff0c;为什么 怎么做 system call 用户操作接口 总结 前言 日常生活中&#xff0c;我们在使用电子设备时&#xff0c;我们所输入执行的每一条指令最终大多都会作用到硬件上&#xff0c;比如下载一款软件最终会下载到硬盘上&am…...