【C++标准库】介绍及使用string类

news2024/9/23 17:16:36

string

  • 一.string类介绍
  • 二.string类的静态成员变量
  • 三.string类的常用接口
    • 1.构造函数(constructor)
    • 2.析构函数(destructor)
    • 3.运算符重载(operator)
      • 1.operator=
      • 2.operator[]
      • 3.operator+=
      • 4.operator+
    • 4.string的四种迭代器(iterator)
      • 1.正向迭代器 iterator
      • 2.反向迭代器 reverse_iterator
      • 3.const修饰的正向迭代器 const_iterator
      • 4.const修饰的反向迭代器 const_reverse_iterator
      • 5.四种迭代器源代码
    • 5.string类对象的容量操作
    • 6.string类对象的修改操作
    • 7.string类对象的查找操作
    • 8.string类对象的遍历操作
      • 1.下标 + []
      • 2.迭代器
      • 3.auto和范围for
        • 1.auto关键字
        • 2.范围for
  • 四.非成员函数:getline()
  • 五.string——>OJ题

一.string类介绍

  C语言中,字符串是以’\0’结尾的一些字符的集合,为了操作方便,C标准库中提供了一些str系列的库函数,但是这些库函数与字符串是分离开的,不太符合OOP的思想,而且底层空间需要用户自己管理,稍不留神可能还会越界访问。
  C++中将string封装为单独的类,string 类是 C++ 标准库中的一个非常重要的类,用于表示和操作字符串。string类位于命名空间std(标准库)下,使用string类记得加上头文件#include,并且使用命名空间using namespace std或者using std::string

//使用时记得加上
#include<string>
using std::string;//或者using namespace std;

//源代码大致框架
namespace std
{
	class string
	{
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	};
}

二.string类的静态成员变量

静态成员变量:static const size_t npos = -1;

int main()
{
	//static const size_t npos = -1;
	//typedef unsigned long long size_t
	//-1的原码:10000000 00000000 00000000 00000001
	//-1的反码:11111111 11111111 11111111 11111110
	//-1的补码:11111111 11111111 11111111 11111111

	//npos:-1的补码按照无符号整形打印出的值,由于静态成员变量,类外使用时加上类域
	cout << string::npos << endl;//32位环境:4294967295

	return 0;
}

三.string类的常用接口

1.构造函数(constructor)

  1. 无参构造string(); 构造空的string类对象,即空字符串。常用。
  2. 有参构造string (const char* s); 用常量字符串来构造string类对象常用。
  3. 拷贝构造string (const string& str); 用str拷贝构造string类对象常用。
  4. string (const string& str, size_t pos, size_t len = npos); 构造从下标pos开始,长度为len的子串,含缺省参数npos。
  5. string (const char* s, size_t n); 构造前n个字符组成的子串。
  6. string (size_t n, char c); 构造n个字符c组成的字符串。
int main()
{
	string s1;
	string s2("hello xzy");
	string s3(s2);
	string s4(s2, 6, 8);
	string s5("hello xzy", 5);
	string s6(10, 'x');

	cout << s1 << endl;//输出:
	cout << s2 << endl;//输出:hello xzy
	cout << s3 << endl;//输出:hello xzy
	cout << s4 << endl;//输出:xzy
	cout << s5 << endl;//输出:hello
	cout << s6 << endl;//输出:xxxxxxxxxx

	return 0;
}

2.析构函数(destructor)

~string(); 程序结束前自动调用,释放堆区动态开辟的资源

3.运算符重载(operator)

1.operator=

  1. string& operator= (const string& str); 常用。

  2. string& operator= (const char* s);

  3. string& operator= (char c);

int main()
{
	string s1;
	string s2;
	string s3;

	//赋值重载
	s1 = "hello xzy";
	s2 = s1;
	s3 = 'v';

	//拷贝构造
	string s4 = s1;

	cout << s1 << endl;//输出:hello xzy
	cout << s2 << endl;//输出:hello xzy
	cout << s3 << endl;//输出:v
	cout << s4 << endl;//输出:hello xzy

	return 0;
}

2.operator[]

  1. char& operator[] (size_t pos); 返回字符引用,用于下标访问,且可以修改。常用。
int main()
{
	string s1("hello xzy");
	s1[6] = 'w';
	s1[7] = 'j';
	s1[8] = '\0';
	cout << s1 << endl;//输出:hello wj

	s1[10] = 'A';//下标越界,内部断言assert报错

	return 0;
}

3.operator+=

  1. string& operator+= (const string& str); 常用。
  2. string& operator+= (const char* s);
  3. string& operator+= (char c);
int main()
{
	string s1("hello xzy");
	string s2(" how are you");
	s1 += s2;
	cout << s1 << endl;

	s1 += "???";
	cout << s1 << endl;

	s1 += '!';
	cout << s1 << endl;

	return 0;
}

在这里插入图片描述

4.operator+

  1. string operator+ (const string& lhs, const string& rhs);
  2. string operator+ (const string& lhs, const char* rhs);
  3. string operator+ (const char* lhs, const string& rhs);
int main()
{
	string s1("hello");
	string s2 = s1 + " world";
	string s3 = "xzy " + s1;
	string s4 = s2 + s3;
	cout << s2 << endl; //hello world
	cout << s3 << endl; //xzy hello
	cout << s4 << endl; //hello worldxzy hello

	return 0;
}

4.string的四种迭代器(iterator)

  迭代器是一种用于遍历容器元素的对象(并非类,而是设计模式中的一种行为模式),它提供了一种通用的访问容器元素的方式,无论容器的类型和数据结构如何。迭代器在C++标准库中被广泛使用,特别是在处理如vector、list、map等容器时。

1.正向迭代器 iterator

返回正向迭代器:可以修改字符串。

  1. iterator begin(); 返回字符串的第一个字符。
  2. iterator end(); 返回字符串最后一个有效字符(不含\0)的下一个字符。

在这里插入图片描述

2.反向迭代器 reverse_iterator

返回反向迭代器:可以修改字符串。

  1. reverse_iterator rbegin(); 返回字符串最后一个有效字符(不含\0)。
  2. reverse_iterator rend(); 返回字符串第一个字符的前一个字符。

在这里插入图片描述

3.const修饰的正向迭代器 const_iterator

返回const修饰的正向迭代器:不可以修改字符串。

  1. const_iterator begin() const;
  2. const_iterator end() const;

4.const修饰的反向迭代器 const_reverse_iterator

返回const修饰的反向迭代器:不可以修改字符串。

  1. const_reverse_iterator rbegin() const;
  2. const_reverse_iterator rend() const;

在这里插入图片描述

5.四种迭代器源代码

int main()
{
	string s1("hello xzy");
	string::iterator it = s1.begin();
	while (it != s1.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;

	string s2("hello xzy");
	string::reverse_iterator rit = s2.rbegin();
	while (rit != s2.rend())
	{
		cout << *rit << " ";
		++rit;
	}
	cout << endl;

	const string s3("hello xzy");
	string::const_iterator cit = s3.begin();
	while (cit != s3.end())
	{
		//*cit += 2; s3不能修改
		cout << *cit << " ";
		++cit;
	}
	cout << endl;

	const string s4("hello xzy");
	string::const_reverse_iterator crit = s4.rbegin();
	while (crit != s4.rend())
	{
		//*crit += 2; s4不能修改
		cout << *crit << " ";
		++crit;
	}
	cout << endl;

	return 0;
}

在这里插入图片描述

5.string类对象的容量操作

  1. size_t size() const; 返回字符串有效字符长度(不包括\0)。常用。
  2. size_t length() const; 返回字符串有效字符长度(不包括\0)。
  3. size_t capacity() const; 返回空间总大小(不包括\0)。常用。
  4. void resize (size_t n); 为字符串预留大于等于n的空间(不包括\0),避免扩容,提高效率。常用。
  5. void clear(); 清空数据,但是一般不清容量。常用。
  6. bool empty() const; 判断是否为空。常用。
  7. void resize (size_t n); 只保留前n个数据。
  8. void resize (size_t n, char c); 保留前n个数据,若n大于容量,后面用字符c补上。

注意:

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

  2. clear()只是将string中有效字符清空,不改变底层空间大小。

  3. resize(size_t n) 与 resize(size_t n, char c)都是将字符串中有效字符个数改变到n个,不同的是当字符个数增多时:resize(n)用 ‘\0’ 来填充多出的元素空间,resize(size_t n, char c)用字符c来填充多出的元素空间。注意:resize在改变元素个数时,如果是将元素个数增多,可能会改变底层容量的大小,如果是将元素个数减少,底层空间总大小不变。

  4. reserve(size_t res_arg=0):为string预留空间,不改变有效元素个数,当reserve的参数小于string的底层空间总大小时,reserver不会改变容量大小。

  5. 在VS2022中的容量变化:有效数据小于16时,数据存放在_buff中,无需扩容;当有效数据大于等于16时,数据存放在_str中,先2倍扩容一次,之后1.5倍扩容。

  6. 再linux中的g++编译器中的容量变化:数据只存放在_str中,容量不足就2倍扩容,感觉相当完美!

//在VS2022下的string类
class string
{
private:
	char* _buff[16]; //有效数据小于16,存放在这里
	char* _str;      //有效数据大于等于16,存放在这里

	size_t _size;
	size_t capacity;
};
int main()
{
	string s;
	size_t sz = s.capacity();
	cout << "capacity changed: " << sz << '\n';
	cout << "making s grow:\n";
	for (int i = 0; i < 100; ++i)
	{
		s.push_back('c');
		if (sz != s.capacity())
		{
			sz = s.capacity();
			cout << "capacity changed: " << sz << '\n';
		}
	}
	cout << "VS2022下的string类的大小:" << sizeof(s) << endl;

	return 0;
}

在这里插入图片描述

int main()
{
	string s1("hello xzy how are you");
	cout << s1.length() << endl;   //21
	cout << s1.size() << endl;     //21
	cout << s1.max_size() << endl; //2147483647
	cout << s1.capacity() << endl; //31

	string s2("hello xzy how are you");
	s2.reserve(100);//扩容:不一定扩100,但一定大于等于n,取决于编译器,Linux中的g++编译器扩的是100
	cout << s2.empty() << endl;    //0
	cout << s2.capacity() << endl; //111
	s2.shrink_to_fit();            //缩容
	cout << s2.capacity() << endl; //31

	string s3("hello xzy how are you");
	s3.resize(9);
	cout << s3 << endl; //hello xzy
	s3.resize(15, 'w');
	cout << s3 << endl; //hello xzywwwwww

	return 0;
}

6.string类对象的修改操作

  1. void push_back (char c); 在字符串后尾插字符c。
  2. void pop_back(); 在字符串尾删一个字符。
  3. string& append (const string& str); 在字符串后追加一个字符串。
  4. string& assign (const string& str, size_t subpos, size_t sublen); 拷贝字符串:从下标为subpos开始,拷贝长度为sublen的字符串到string类对象里面。
  5. string& insert (size_t pos, const string& str); 在pos位置处插入字符串到string类对象里面。(由于效率问题(移动数据),谨慎使用)。
  6. string& erase (size_t pos = 0, size_t len = npos); 从pos位置开始删除长度为npos个字符。(由于效率问题(移动数据),谨慎使用)。
  7. string& replace (size_t pos, size_t len, const string& str); 从pos位置开始的长度为len的子串,替换为str。(伴随着插入与删除,效率低,谨慎使用)。
  8. void swap (string& str); 交换字符串。
int main()
{
	string s1("hello xzy");
	s1.push_back('!');
	cout << s1 << endl; //hello xzy!
	s1.pop_back();
	cout << s1 << endl; //hello xzy
	s1.append(" how are you");
	cout << s1 << endl; //hello xzy! how are you

	//可以用+=取代尾插
	s1 += "???";
	cout << s1 << endl; //hello xzy! how are you???

	string s2("hello xzy!!!");
	string s3;
	s3.assign(s2, 6, 3);
	cout << s3 << endl; //xzy

	string s4("hello xzy");
	s4.insert(0, "hello wj ");
	cout << s4 << endl; //hello wj hello xzy

	string s5("hello xzy!!!");
	s5.erase(9, 2);
	cout << s5 << endl; //hello xzy!

	string s6("hello xzy!!!");
	s6.replace(6, 5, "wj");
	cout << s6 << endl; //hello wj!

	string s7("hello x hello x");
	string tmp;
	tmp.reserve(s7.size());
	for (auto ch : s7)
	{
		if (ch == 'x')
			tmp += "wj";
		else
			tmp += ch;
	}
	cout << tmp << endl; //hello wj hello wj
	s7.swap(tmp);
	cout << s7 << endl;  //hello wj hello wj

	return 0;
}
  1. const char* c_str() const; 返回C格式字符串。方便调用C中的接口
int main()
{
	string file;
	cin >> file;

	//c_str()函数用于调用C语言的函数,若直接传string,类型不符合(类和指针)
	FILE* fout = fopen(file.c_str(), "r");
	if (fout == NULL)
	{
		perror("open file fail!");
		exit(1);
	}
	char ch = fgetc(fout);
	while (ch != EOF)
	{
		cout << ch;
		ch = fgetc(fout);
	}
	fclose(fout);
	fout = NULL;

	return 0;
}

7.string类对象的查找操作

  1. string substr (size_t pos = 0, size_t len = npos) const; 找子串:返回从pos位置开始,长度为npos的string类。
  2. size_t find (char c, size_t pos = 0) const; 从字符串pos位置开始往后找字符c,返回该字符在字符串中的位置。
  3. size_t rfind (char c, size_t pos = npos) const; 从字符串pos位置开始往前找字符c,返回该字符在字符串中的位置。
  4. size_t find_first_of (const char* s, size_t pos = 0) const; 从字符串pos位置开始从前往后找字符串s中出现的字符,返回该字符在字符串中的位置。
  5. size_t find_last_of (const char* s, size_t pos = npos) const; 从字符串pos位置开始从后往前找字符串s中出现的字符,返回该字符在字符串中的位置。
  6. size_t find_first_not_of (const char* s, size_t pos = 0) const; 从字符串pos位置开始从前往后找字符串s中没有出现的字符,返回该字符在字符串中的位置。
  7. size_t find_last_not_of (const char* s, size_t pos = npos) const; 从字符串pos位置开始从后往前找字符串s中没有出现的字符,返回该字符在字符串中的位置。
int main()
{
	//suffix:后缀

	string s1("test.cpp");
	size_t pos1 = s1.find(".");
	string suffix1 = s1.substr(pos1);
	cout << suffix1 << endl; //.cpp

	string s2("test.cpp.zip");
	size_t pos2 = s2.rfind(".");
	string suffix2 = s2.substr(pos2);
	cout << suffix2 << endl; //.zip

	string s3("hello xzy");
	size_t found = s3.find_first_of("xzy");
	while (found != string::npos)
	{
		s3[found] = '*';
		found = s3.find_first_of("xzy", found + 1);
	}
	cout << s3 << endl; //hello ***

	string str1("/user/bin/man");
	cout << endl << str1 << "的路径名与文件名如下:" << endl;
	size_t found1 = str1.find_last_of("/\\");
	cout << "path:" << str1.substr(0, found1) << endl;
	cout << "file:" << str1.substr(found1 + 1) << endl;

	string str2("c:\\windows\\winhelp.exe");
	cout << endl << str2 << "的路径名与文件名如下:" << endl;
	size_t found2 = str2.find_last_of("/\\");
	cout << "path:" << str2.substr(0, found2) << endl;
	cout << "file:" << str2.substr(found2 + 1) << endl;

	return 0;
}

8.string类对象的遍历操作

1.下标 + []

int main()
{
	string s1("hello xzy");
	//1.下标+[]
	for (int i = 0; i < s1.size(); i++)
	{
		s1[i] += 2;//可以修改
		cout << s1[i] << " ";
	}
	cout << endl << s1 << endl;
	return 0;
}

在这里插入图片描述

2.迭代器

int main()
{
	string s1("hello xzy");
	//2.迭代器
	string::iterator it = s1.begin();
	while (it != s1.end())
	{
		*it += 2;//可以修改
		cout << *it << " ";
		++it;
	}
	cout << endl << s1 << endl;
	return 0;
}

在这里插入图片描述

3.auto和范围for

int main()
{
	string s1("hello xzy");
	//3.范围for:字符赋值,自动迭代,自动判断结束
	//  底层就是迭代器
	for (auto ch : s1)
	{
		ch += 2;//修改ch对于s1无影响,ch是它的拷贝
		cout << ch << ' ';
	}
	cout << endl << s1 << endl;
	return 0;
}

在这里插入图片描述

int main()
{
	string s1("hello xzy");
	for (auto& ch : s1)//引用:取别名,就可以修改s1
	{
		ch += 2;
		cout << ch << ' ';
	}
	cout << endl << s1 << endl;
	return 0;
}

在这里插入图片描述

1.auto关键字
  1. 在早期C/C++中auto的含义是:使用auto修饰的变量,是具有自动存储器的局部变量,后来这个不重要了。C++11中,标准委员会变废为宝赋予了auto全新的含义即:auto不再是一个存储类型指示符,而是作为一个新的类型指示符来指示编译器auto声明的变量必须由编译器在编译时期 推导而得

  2. 用auto声明指针类型时,用auto和auto*没有任何区别,但用auto声明引用类型时则必须加&。

  3. 当在同一行声明多个变量时,这些变量必须是相同的类型,否则编译器将会报错,因为编译器实际只对第一个类型进行推导,然后用推导出来的类型定义其他变量。

  4. auto不能作为函数的参数,可以做返回值,但是建议谨慎使用。

  5. auto不能直接用来声明数组。

#include<map>
//auto不能做参数
//void func1(auto a) error
//{}

//auto可以做返回值,但是建议谨慎使用
auto func2()
{
	return 2;
}

int main()
{
	int a = 10;
	auto b = a;//编译期间自动推导类型
	auto c = 'a';
	auto d = func2();
	//auto e; auto必须初始化,否则不知道开多少空间

	int x = 10;
	auto y = &x;
	auto* z = &x;//可以不写*
	auto& m = x;//必须加上&

	auto aa = 1, bb = 2;//right
	//auto cc = 3, dd = 4.0; error必须始终推导为同一类型
	//auto array[] = { 4, 5, 6 }; error数组不能具有其中包含“auto”的元素类型

	// auto 的价值
	map<string, string> dict; //初始化二叉树
	//map<string, string>::iterator mit = dict.begin();
	auto mit = dict.begin();

	cout << typeid(mit).name() << endl;

	return 0;
}

在这里插入图片描述

2.范围for
  1. 对于一个有范围的集合而言,由程序员来说明循环的范围是多余的,有时候还会容易犯错误。因此C++11中引入了基于范围的for循环。for循环后的括号由冒号“ :”分为两部分:第一部分是范围内用于迭代的变量,第二部分则表示被迭代的范围,自动迭代,自动取数据,自动判断结束。

  2. 范围for可以作用到数组和容器对象上进行遍历。

  3. 范围for的底层很简单,容器遍历实际就是替换为迭代器,这个从汇编层也可以看到。

int main()
{
	int array[] = { 1, 2, 3, 4, 5 };

	//范围for适用于《容器》和《数组》
	// C++98的遍历
	for (int i = 0; i < sizeof(array) / sizeof(array[0]); i++)
	{
		cout << array[i] << ' ';
	}
	cout << endl;

	// C++11的遍历
	for (auto& i : array)
	{
		cout << i << ' ';
	}
	cout << endl;

	return 0;
}

四.非成员函数:getline()

  1. istream& getline (istream& is, string& str, char delim); delim:分隔符
  2. istream& getline (istream& is, string& str);

类似C语言中的scanf(“%s”, str),但是其遇到空格会停止;
C++中引入了getline优化了scanf遇到的问题,默认遇到\n才停止,也可以自定义停止字符delim。

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

在这里插入图片描述

#include <iostream>
#include<string>
using namespace std;

int main() 
{
    string str;
    getline(cin, str);
    size_t pos = str.rfind(' ');
    string sub = str.substr(pos + 1);
    cout << sub.size() << endl;
}

五.string——>OJ题

  1. 把字符串转换成整数(atoi)
  2. 字符串相加
  3. 反转字符串
  4. 字符串最后一个单词的长度
  5. 验证回文串
  6. 反转字符串||
  7. 字符串中的第一个唯一字符
  8. 反转字符串中的单词|||
  9. 字符串相乘

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1964222.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SecureCrt设置豆沙绿

绿豆沙色能有效的减轻长时间用电脑的用眼疲劳&#xff01; 色调&#xff1a;85&#xff0c;饱和度&#xff1a;123&#xff0c;亮度&#xff1a;205&#xff1b;RGB颜色红&#xff1a;199&#xff0c;绿&#xff1a;237&#xff0c;蓝&#xff1a;204&#xff1b; 十六进制颜色…

3步阐述搜索框做了什么事情

搜索功能是几乎每个产品的通用标配功能&#xff0c;一个看似简单的搜索框背后&#xff0c;其实隐含了大量的设计思考和技术壁垒。本文将从三个部分阐述&#xff0c;为何搜索框并不简单。 本文将从搜索场景的思考、基于步骤的搜索设计以及搜索数据的追踪3个部分&#xff0c;对产…

今日arXiv最热大模型论文:北京大学最新综述:视觉大模型中的漏洞与攻防对抗

近年来&#xff0c;视觉语言大模型&#xff08;LVLM&#xff09;在文本转图像、视觉问答等任务中大放异彩&#xff0c;背后离不开海量数据、强大算力和复杂参数的支撑。 但是&#xff01;大模型看似庞大的身躯背后却有一颗脆弱的“心脏”&#xff0c;极易受到攻击。攻击者可以…

史上最全,网工必考证书大盘点,竟然有20多个?

最近很多朋友来咨询&#xff0c;作为网工能考什么证书&#xff1f;证书那么多要怎么选择&#xff1f;哪个性价比高、哪个回报大等等等等的问题。 不难看出&#xff0c;大家最近这个想要学习和提升的势头很猛&#xff0c;毕竟现在这个环境下&#xff0c;属实是不好过了&#xff…

FPGA开发——数码管的使用(二)

一、概述 在上一篇文章中我们针对单个数码管的静态显示和动态显示进行了一个设计和实现&#xff0c;这篇文章中我们针对多个数码管同时显示进行一个设计。这里和上一篇文章唯一不同的是就是数码管位选进行了一个改变&#xff0c;原来是单个数码管的显示&#xff0c;所以位选就直…

Android Studio运行报错:module java.base dose not “opens java.io“ to unnamed module

今天第一次使用Android Studio运行一个安卓工程&#xff0c;报如图错误,应该是环境问题。 解决&#xff1a; 右上角的设置图标->settings->Buid,Execution,Deployment->Build Tools->Gradle->Gradle JDK->选择本地环境的java_home jdk&#xff08;怎么安装…

docker镜像不可用

现在阿里、163等docker镜像基本不能使用&#xff0c;不能pull镜像了。 1.腾讯云内部 腾讯云服务器内部可用镜像&#xff08;当然&#xff0c;需要先有一个腾讯云服务器&#xff09;&#xff1a;https://mirror.ccs.tencentyun.com 配置方法&#xff0c;vi /etc/docker/daemon…

C++—— IO流

一、C语言的输入与输出 C语言中我们用到的最频繁的输入输出方式就是scanf()和printf()。 scanf()&#xff1a;从标准输入设备&#xff08;键盘&#xff09;中读取数据&#xff0c;并将值存放在变量中。 printf()&#xff1a;将指定的文字/字符串输出到标准输出设备&#xff08;…

Python 聊天机器人项目-8-学习使用 NLTK 和 Keras 构建您的第一个聊天机器人

一、前言 该文章仅作为个人学习使用 二、正文 项目源代码&#xff1a;Python 聊天机器人项目 - 学习使用 NLTK 和 Keras 构建您的第一个聊天机器人 - DataFlair (data-flair.training) 数据集&#xff1a;https://data-flair.training/blogs/download-python-chatbot-data-…

Web3时代:科技与物联网的完美结合

随着信息技术的不断进步和物联网应用的普及&#xff0c;Web3技术作为下一代互联网的重要组成部分&#xff0c;正逐渐与物联网技术深度融合&#xff0c;共同开创了新的科技时代。本文将深入探讨Web3技术与物联网的结合&#xff0c;探索它们如何共同推动未来科技发展的新趋势和应…

【32单片机篇】项目:智能排队控制系统

一、项目需求 1. 红外传感器检测有人通过并计数&#xff1b; 2. 计数值显示在LCD1602&#xff1b; 3. 允许通过时&#xff0c;LED1闪烁&#xff0c;蜂鸣器不响&#xff0c;继电器不闭合&#xff1b; 4. 不允许通过时&#xff0c;LED2闪烁&#xff0c;蜂鸣器响&#xff0c;继电…

工信部:2024上半年我国信息安全领域收入909亿元

2024年上半年软件业经济运行情况 上半年&#xff0c;我国软件和信息技术服务业&#xff08;以下简称“软件业”&#xff09;运行态势良好&#xff0c;软件业务收入和利润均保持两位数增长&#xff0c;软件业务出口收入增速由负转正&#xff0c;主要大省持续向好发展。 一、总…

光纤基础科普

这部分主要介绍光纤的常见接口&#xff08;四种&#xff09;、光纤传输的种类、光模块的封装类型。 文章目录 一、光纤的常见接口二、光模块封装三、光纤传输种类 一、光纤的常见接口 光纤接口种类繁多&#xff0c;这里给出常用的四种 &#xff08;1&#xff09;SC 型光纤接…

C++静态成员变量和静态成员函数

演示代码如下&#xff1a; #include<iostream> using namespace std;class Person { public://静态成员函数 所有对象共享一个函数&#xff0c;且只能调用静态成员变量 ******static void func(){m_A 300;cout << "静态成员函数调用" << endl;}/…

Charles抓包工具系列文章(七)-- Rewrite工具的应用示例

一、背景 客户端通过域名访问后端服务,在api网关层,会判断path的前缀,默认/api开头的请求都转发至后端服务A。 当前缀是/assist/api开头,请求将转发至后端服务B(部署在192.168.80.226,便于测试对比) 在不改动kong网关配置的情况下,现需要把后者的请求转发至192.168.…

RxJava基础使用

Rx思想 事件从起点流向终点。 过程中可以对事件进行拦截&#xff0c;拦截时可以对事件进行处理&#xff0c;处理后将处理后的事件继续流向终点。 终点接收上一次处理后的事件。 获取网络图片并显示 基础实现 使用Observable.just(path) 创建图片路径的Observable。 使用m…

reshape函数及MATLAB应用

reshape 函数在 MATLAB 中是一个非常有用的函数&#xff0c;通过重新排列现有元素来重构数组。它允许你重新调整数组&#xff08;或矩阵&#xff09;的尺寸&#xff0c;而不改变其数据。这个函数特别适用于当你需要将一个矩阵或数组从一种结构转换为另一种结构时&#xff0c;只…

黑神话悟空是什么游戏 黑神话悟空配置要求 黑神话悟空好玩吗值得买吗 黑神话悟空苹果电脑可以玩吗

《黑神话&#xff1a;悟空》的类型定义是一款单机动作角色扮演游戏&#xff0c;但实际体验后会发现&#xff0c;游戏在很多设计上采用了「魂like」作品的常见元素。根据个人上手试玩&#xff0c;《黑神话&#xff1a;悟空》的推进节奏比较接近魂类游戏&#xff0c;Boss战也更像…

数据结构--双链表,循环链表,静态链表代码(王道书上代码手敲!!!)c++

目录 1.带头结点的双链表的初始化&#xff0c;判断链表是否为空&#xff0c;前插&#xff0c;后插&#xff0c;按位序插&#xff0c;删除后继节点&#xff0c;按位查找&#xff0c;按之查找&#xff0c;清空链表&#xff0c;销毁链表&#xff0c;遍历打印列表操作 2. 循环单链…

linux目录结构和重要文件

1. 目录介绍 操作Linux命令行&#xff0c;最基本的对象就是目录和文件&#xff0c;因为Linux中一切事物都是基于文件的&#xff0c;而目录就是文件的文件夹&#xff0c;所以接下来对一些基础且核心的文件目录管理命令进行说明。 1.1 目录结构 Linux系统目录结构是一个有层次…