std::string详解

openssl sm2 加解密 1.SM2算法 openssl 1.1.1以后版本提供了对国密SM2算法的支持。源码的cryto/include/internall目录下有sm2,sm3,sm4的设计实现,但是无法直接调用,因此通过openssl的evp接口实现国密SM2算法的加解密。 SM2公钥格式:公钥:04|X|Y,共65字节;私钥格式:整数,共32字节。密文格式结构体为,typedef struct SM2Cipher_st { ASN1_INTEGER *xCoordinate; ......... 阅读详情

之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够、字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是100%)的需要。我们可以用 = 进行赋值操作,== 进行比较,+ 做串联(是不是很简单?)。我们尽可以把它看成是C++的基本数据类型。

标准模板库(STL)提供了一个std::string类,其是std::basic_string的一个特化,它是一个容器类,可把字符串当作普通类型来使用,并支持比较、连接、遍历、STL算法、复制、赋值等等操作,这个类定义在<string>头文件中。

#include <string> //注意这里不是string.h string.h是C字符串头文件
1.声明一个C++字符串
std::string类的构造函数

声明一个字符串变量很简单:
string Str;
这样我们就声明了一个字符串变量,但既然是一个类,就有构造函数和析构函数。上面的声明没有传入参数,所以就直接使用了string的默认的构造函数,这个函数所作的就是把Str初始化为一个空字符串。String类的构造函数和析构函数如下:
a) string s(); //生成一个空字符串s
b) string s(str) //拷贝构造函数 生成str的复制品string(const string& str)
c) string s(str,stridx) //将字符串str内"始于位置stridx"的部分当作字符串的初值
d) string s(const string& str, size_type pos,strlen) //将字符串str内"始于pos且长度顶多strlen"的部分作为字符串的初值
e) string s(const char *s) //将C字符串作为s的初值
f) string s(const char* cstr, size_type n) //使用字符串str的前n个字符初始化作为字符串s的初值。
g) string s(int num,char c) //生成一个字符串,包含num个c字符
h) string s(beg,end) //以区间beg;end(不包含end)内的字符作为字符串s的初值
i) s.~string() //销毁所有字符,释放内存
都很简单,我就不解释了。

当构造的string太长而无法表达时会抛出length_error异常


2.字符串操作函数
这里是C++字符串的重点,我先把各种操作函数罗列出来,不喜欢把所有函数都看完的人可以在这里找自己喜欢的函数,再到后面看他的详细解释。
a) =,assign() //赋以新值
b) swap() //交换两个字符串的内容
c) +=,append(),push_back() //在尾部添加字符
d) insert() //插入字符
e) erase(int nStart,int nEnd) //删除nStart—nEnd位置字符
f) clear() //删除全部字符
g) replace() //替换字符
h) + //串联字符串
i) ==,!=,<,<=,>,>=,compare() //比较字符串
j) size(),length() //返回字符数量
k) max_size() //返回字符的可能最大个数
l) empty() //判断字符串是否为空
m) capacity() //返回重新分配之前的字符容量
n) reserve() //保留一定量内存以容纳一定数量的字符
o) [ ], at() //存取单一字符
p) >>,getline() //从stream读取某值
q) << //将谋值写入stream
r) copy() //将某值赋值为一个C_string
s) c_str() //将内容以C_string返回
t) data() //将内容以字符数组形式返回
u) substr() //返回某个子字符串
v)查找函数
w)begin() end() //提供类似STL的迭代器支持
x) rbegin() rend() //逆向迭代器
y) get_allocator() //返回配置器
下面详细介绍:

2.1 C++字符串和C字符串的转换
C ++提供的由C++字符串得到对应的C_string的方法是使用data()、c_str()和copy(),其中,data()以字符数组的形式返回字符串内容,但并不添加’’。c_str()返回一个以‘’结尾的字符数组,而copy()则把字符串的内容复制或写入既有的c_string或 字符数组内。C++字符串并不以’’结尾。我的建议是在程序中能使用C++字符串就使用,除非万不得已不选用c_string。由于只是简单介绍,详细介绍掠过,谁想进一步了解使用中的注意事项可以给我留言(到我的收件箱)。我详细解释。

2.2 大小和容量函数
一个C++字符 串存在三种大小:

a) 现有的字符数,函数是size()和length(),他们等效。Empty()用来检查字符串是否为空。

b) max_size() 这个大小是指当前C++字符串最多能包含的字符数,很可能和机器本身的限制或者字符串所在位置连续内存的大小有关系。我们一般情况下不用关心他,应该大小足够我们用的。但是不够用的话,会抛出length_error异常

c) capacity()重新分配内存之前 string所能包含的最大字符数。这里另一个需要指出的是reserve()函数,这个函数为string重新分配内存。重新分配的大小由其参数决定, 默认参数为0,这时候会对string进行非强制性缩减。

还有必要再重复一下C++字符串和C字符串转换的问 题,许多人会遇到这样的问题,自己做的程序要调用别人的函数、类什么的(比如数据库连接函数Connect(char*,char*)),但别人的函数参 数用的是char*形式的,而我们知道,c_str()、data()返回的字符数组由该字符串拥有,所以是一种const char*,要想作为上面提及的函数的参数,还必须拷贝到一个char*,而我们的原则是能不使用C字符串就不使用。那么,这时候我们的处理方式是:如果 此函数对参数(也就是char*)的内容不修改的话,我们可以这样Connect((char*)UserID.c_str(), (char*)PassWD.c_str()),但是这时候是存在危险的,因为这样转换后的字符串其实是可以修改的(有兴趣地可以自己试一试),所以我强调除非函数调用的时候不对参数进行修改,否则必须拷贝到一个char*上去。当然,更稳妥的办法是无论什么情况都拷贝到一个char*上去。同时我们也祈 祷现在仍然使用C字符串进行编程的高手们(说他们是高手一点儿也不为过,也许在我们还穿开裆裤的时候他们就开始编程了,哈哈…)写的函数都比较规范,那样 我们就不必进行强制转换了。
2.3元素存取

我们可以使用下标操作符[]和函数at()对元素包含的字符进行访问。但是应该注意的是操作符[]并不检查索引是否有效(有效索引0~str.length()),如果索引失效,会引起未定义的行为。而at()会检查,如果使用 at()的时候索引无效,会抛出out_of_range异常。
有一个例外不得不说,const string a;的操作符[]对索引值是a.length()仍然有效,其返回值是’’。其他的各种情况,a.length()索引都是无效的。举例如下:
const string Cstr("const string");
string Str("string");

Str[3]; //ok
Str.at(3); //ok

Str[100]; //未定义的行为
Str.at(100); //throw out_of_range

Str[Str.length()] //未定义行为
Cstr[Cstr.length()] //返回 ‘’
Str.at(Str.length());//throw out_of_range
Cstr.at(Cstr.length()) ////throw out_of_range

我不赞成类似于下面的引用或指针赋值:
char& r=s[2];
char* p= &s[3];
因为一旦发生重新分配,r,p立即失效。避免的方法就是不使用。


遍历所有字符,这可由C风格的索引或STL迭代子来完成(如果无需修改,应使用const_iterator)。

std::string name = "marius";

for(size_t i = 0; i < name.length(); ++i)

std::cout << name[i];

 

for(std::string::const_iterator cit = name.begin(); cit != name.end(); ++cit)

std::cout << *cit;

 

for(std::string::iterator it = name.begin();it != name.end(); ++it)

*it = toupper(*it);
2.4比较函数
C ++字符串支持常见的比较操作符(>,>=,<,<=,==,!=),甚至支持string与C-string的比较(如 str<"hello")。在使用>,>=,<,<=这些操作符的时候是根据"当前字符特性"将字符按字典顺序进行逐一得 比较。字典排序靠前的字符小,比较的顺序是从前向后比较,遇到不相等的字符就按这个位置上的两个字符的比较结果确定两个字符串的大小。同时,string ("aaaa") <string(aaaaa)。
另一个功能强大的比较函数是成员函数compare()。他支持多参数处理,支持用索引值和长度定位子串来进行比较。他返回一个整数来表示比较结果,返回值意义如下:0-相等 〉0-大于 <0-小于。举例如下:
string s("abcd");

s.compare("abcd"); //返回0
s.compare("dcba"); //返回一个小于0的值
s.compare("ab"); //返回大于0的值

s.compare(s); //相等
s.compare(0,2,s,2,2); //用"ab"和"cd"进行比较 小于零
s.compare(1,2,"bcx",2); //用"bc"和"bc"比较。
怎么样?功能够全的吧!什么?还不能满足你的胃口?好吧,那等着,后面有更个性化的比较算法。先给个提示,使用的是STL的比较算法。什么?对STL一窍不通?靠,你重修吧!

2.5 更改内容
这在字符串的操作中占了很大一部分。

首先讲赋值,第一个赋值方法当然是使用操作符=,新值可以是string(如:s=ns) 、c_string(如:s="gaint")甚至单一字符(如:s=’j’)。还可以使用成员函数assign(),这个成员函数可以使你更灵活的对字符串赋值。还是举例说明吧:
s.assign(str); //不说
s.assign(str,1,3);//如果str是"iamangel" 就是把"ama"赋给字符串
s.assign(str,2,string::npos);//把字符串str从索引值2开始到结尾赋给s
s.assign("gaint"); //不说
s.assign("nico",5);//把’n’ ‘I’ ‘c’ ‘o’ ‘’赋给字符串
s.assign(5,’x’);//把五个x赋给字符串
把字符串清空的方法有三个:s="";s.clear();s.erase();(我越来越觉得举例比说话让别人容易懂!)。
string提供了很多函数用于插入(insert)、删除(erase)、替换(replace)、增加字符。
先说增加字符(这里说的增加是在尾巴上),函数有 +=、append()、push_back()。举例如下:
s+=str;//加个字符串
s+="my name is jiayp";//加个C字符串
s+=’a’;//加个字符

s.append(str);
s.append(str,1,3);//不解释了 同前面的函数参数assign的解释
s.append(str,2,string::npos)//不解释了

s.append("my name is jiayp");
s.append("nico",5);
s.append(5,’x’);
2.5.1、在字符串结尾插入其他元素。
s.push_back(‘a’);//这个函数只能增加单个字符 对STL熟悉的理解起来很简单
2.5.2、 在指定位置插入字符串或字符。

也许你需要在string中间的某个位置插入字符串,这时候你可以用insert()函数,这个函数需要你指定一个安插位置的索引,被插入的字符串将放在这个索引的后面。
s.insert(0,"my name");
s.insert(1,str);
这 种形式的insert()函数不支持传入单个字符,这时的单个字符必须写成字符串形式(让人恶心)。既然你觉得恶心,那就不得不继续读下面一段话:为了插 入单个字符,insert()函数提供了两个对插入单个字符操作的重载函数:insert(size_type index,size_type num,chart c)和insert(iterator pos,size_type num,chart c)。其中size_type是无符号整数,iterator是char*,所以,你这么调用insert函数是不行的:insert(0,1, ’j’);这时候第一个参数将转换成哪一个呢?所以你必须这么写:insert((string::size_type)0,1,’j’)!第二种形式指 出了使用迭代器安插字符的形式,在后面会提及。顺便提一下,string有很多操作是使用STL的迭代器的,他也尽量做得和STL靠近。
删除函数erase()的形式也有好几种(真烦!),替换函数replace()也有好几个。举例吧:
string s="il8n";
s.replace(1,2,"nternationalizatio");//从索引1开始的2个替换成后面的C_string

2.5.3、 删除字符串的某一部分。
s.erase(13);//从索引13开始往后全删除
s.erase(7,5);//从索引7开始往后删5个

2.6提取子串和字符串连接
题取子串的函数是:substr(),形式如下:
s.substr();//返回s的全部内容
s.substr(11);//从索引11往后的子串
s.substr(5,6);//从索引5开始6个字符
把两个字符串结合起来的函数是+。(谁不明白请致电120)

2.7输入输出操作
1.>> 从输入流读取一个string。
2.<< 把一个string写入输出流。
另一个函数就是getline(),他从输入流读取一行内容,直到遇到分行符或到了文件尾。

2.8搜索与查找

std::string类的查找函数
查找函数很多,功能也很强大,包括了:
find()
rfind()
find_first_of()
find_last_of()
find_first_not_of()
find_last_not_of()

 
这些函数返回符合搜索条件的字符区间内的第一个字符的索引,没找到目标就返回npos。所有的函数的参数说明如下:
第一个参数是被搜寻的对象。第二个参数(可有可无)指出string内的搜寻起点索引,第三个参数(可有可无)指出搜寻的字符个数。比较简单,不多说不理解的可以向我提出,我再仔细的解答。当然,更加强大的STL搜寻在后面会有提及。
最 后再说说npos的含义,string::npos的类型是string::size_type,所以,一旦需要把一个索引与npos相比,这个索引值必须是string::size)type类型的,更多的情况下,我们可以直接把函数和npos进行比较(如:if(s.find("jia")== string::npos))。

3.1、使用STL算法

 

std::string name = "marius";

// 使字符串全为大写

std::transform(name.begin(), name.end(), name.begin(),toupper);

std::string name = "marius";

// 升序排列字符串

std::sort(name.begin(), name.end());

std::string name = "marius";

// 反转字符串

std::reverse(name.begin(), name.end());

bool iswhitespace(char ch)

{

return  ch == ' ' || ch == 't' || ch == 'v' ||

ch == 'r' || ch == 'n';

}

 

std::string name = " marius  ";

// 删除空白字符

std::string::iterator newend = std::remove_if(name.begin(), name.end(), iswhitespace);

name.erase(newend);

 

 

std::string类的替换函数

 

函数1:
std::string & replace(size_type pos1, size_type n1, const std::string & str, size_type pos2 = 0, size_type n2 = npos);

该函数的作用:使用str字符串从位置pos2开始的n2个字符,替换当前字符串从pos1位置开始处的n1个字符。
可以这样理解:该函数将当前字符串从pos1开始的n1个字符全部删除,然后再用str整个字符串或者str从pos2开始的n2个字符,从pos1位置开始填入到当前字符串中。

提醒:如果n1或者n2的数值超出了对应字符串的长度,以实际长度为准,不会出现访问越界的情况。

注意:
a、如果pos1指定的位置超出当前字符串的范围,抛出std::out_of_range异常,不捕捉将导致coredump。
b、如果pos2指定的位置超出替换字符串str的范围,抛出std::out_of_range异常,不捕捉将导致coredump。

函数2:
std::string& replace(size_type pos, size_type n1, const char * s, size_type n2);

该函数的作用:使用字符串s的前n2个字符,替换当前字符串从pos位置开始处的n1个字符。
可以这样理解:函数将当前字符串从pos开始的n1个字符全部删除,然后再用字符串s的前n2个字符填入到当前字符串中。类似于函数1的pos2等于0,必须指定n2的这种情况,但也有一点的差别,下面会注意里描述这种差别。
注意:
a、如果pos指定的位置超出当前字符串的范围,抛出std::out_of_range异常,不捕捉将导致coredump。
b、该函数不会判断字符串s和n2的大小关系,它严格地从s起始处拷贝n2个字符到指定位置。如果n2表示的长度超出了s的范围,它会读取s后面的内存空间,有可能会因为内存访问越界而coredump。但函数1的n2可以超出范围,它以实际长度为准。

函数3:
std::string& replace(size_type pos, size_type n1, const char* s);

该函数的作用:使用以''为结尾的字符串s,替换当前字符串从pos位置开始处的n1个字符。
可以这样理解:函数将当前字符串从pos开始的n1个字符全部删除,然后再用字符串s从开始到以''结束的所有字符,从pos位置开始填入到当前字符串中。

注意:如果pos指定的位置超出当前字符串的范围,抛出std::out_of_range异常,不捕捉将导致coredump。

函数4:
std::string& replace(size_type pos, size_type n1, size_type n2, char c);

该函数的作用:使用n2个c表示的字符,替换当前字符串从pos位置开始处的n1个字符。
可以这么理解:函数将当前字符串从pos开始的n1个字符全部删除,然后再用n2个c字符,从pos位置开始填入到当前字符串中。

注意:如果pos指定的位置超出当前字符串的范围,抛出std::out_of_range异常,不捕捉将导致coredump。

函数5:
std::string& replace(iterator i1, iterator i2, const std::string& str);

该函数的作用:使用字符串str,替换当前字符串[i1,i2)之间的字符。

函数6:
std::string& replace(iterator i1, iterator i2, const char* s, size_type n);

该函数的作用:使用字符串s的前n个字符,替换当前字符串[i1,i2)之间的字符。

函数7:
std::string& replace(iterator i1, iterator i2, const char* s);

该函数的作用:使用以''结尾的字符串s,替换当前字符串[i1,i2)之间的字符。

函数8:
std::string& replace(iterator i1, iterator i2, size_type n, char c);

该函数的作用:使用n个c表示的字符,替换当前字符串[i1,i2)之间的字符。

std::string类的内部类型定义

typedef traits traits_type;

typedef typename traits::char_type value_type;

typedef size_t size_type;

typedef Allocator allocator_type;

typedef ptrdiff_t difference_type;

typedef Allocator allocator_type;

typedef Allocator allocator_type;

typedef Allocator allocator_type;

typedef charT& reference; typedef const charT& const_reference; typedef charT* pointer; typedef const charT* const_pointer; typedef pointer iterator; typedef const_pointer const_iterator; typedef ::reverse_iterator reverse_iterator; typedef ::reverse_iterator const_reverse_iterator; static const size_type npos = static_cast(-1);

std::string类的赋值运算符

string& operator= (const char* s);
string& operator= (char c);
string& operator+= (const string& rhs);
string& operator+= (const char* s);
string& operator+= (char c);
string operator+ (const string & lhs, const string & rhs);
string operator+ (const char* lhs, const string & rhs);
string operator+ (char lhs, const string & rhs);
string operator+ (const string & lhs, const char* rhs);
string operator+ (const string & lhs, char rhs);

std::string类的逻辑运算符

bool operator== (const string & lhs, const string & rhs);
bool operator== (const char* lhs, const string & rhs);
bool operator== (const string & lhs, const char* rhs);
bool operator!= (const string & lhs, const string & rhs);
bool operator!= (const char* lhs, const string & rhs);
bool operator!= (const string & lhs, const char* rhs);
bool operator< (const string & lhs, const string & rhs);
bool operator< (const char* lhs, const string & rhs);
bool operator< (const string & lhs, const char* rhs);
bool operator> (const string & lhs, const string & rhs);
bool operator> (const char* lhs, const string & rhs);
bool operator> (const string & lhs, const char* rhs);
bool operator<= (const string & lhs, const string & rhs);
bool operator<= (const char * lhs, const string & rhs);
bool operator<= (const string & lhs, const char * rhs);
bool operator>= (const string & lhs, const string & rhs);
bool operator>= (const char* lhs, const string & rhs);
bool operator>= (const string & lhs, const char* rhs);

istream& operator >> (istream&, string &);
ostream& operator << (ostream&, const string &);
istream& getline (istream&, string &, char delim = 'n');

IDA查看std::string的各种操作 相对C语言来说,C++中增加了很多特性,例如,构造函数、析构函数、异常处理等,因此,从汇编级别的语言看,C++就复杂很多。下面使用IDA工具查看std::string的一些操作背后的实现。以下程序在编译,g++版本为。std::string提供了更高层次的字符串操作,并且提供了很多的方法,与C风格字符串相比,使用起来更加方便,但是,在这些方法的底层,编译器默默做了很多事情。 阅读详情

相关推荐

C++ 字符串详解:从基础到进阶全面掌握 std::string

通过本篇文章,你已经了解了在 C++ 中的基本使用方法,以及如何在算法中高效应用字符串操作。希望这篇文章能帮助你从零开始掌握 C++ 字符串的相关技巧,并在实际编程中游刃有余。对于初学者来说,掌握这些基础操作、算法技巧和性能优化手段,可以帮助你在面对字符串相关的算法问题时,不仅能解决问题,还能编写出高效、优雅的代码。

m0_73147661的博客 1349

C++ 基础: std::string

std::string 快速上手

Mr.Sugarcane 1万+

C++中std::string用法详解

本文介绍了Linux C++开发中std::string的核心用法,包括初始化、遍历、拼接、查找替换、截取删除等高频操作,并提供了配置文件解析的实战示例。std::string相比C风格字符串更安全高效,能自动管理内存,避免越界和泄漏问题。文章重点讲解了常见易错点,如边界检查、返回值判断等,并给出可直接运行的代码示例。通过掌握这些基础用法,可以满足80%的日常开发需求,同时为进一步学习字符串转换、比较和性能优化打下基础。

凡人叶枫的博客 658

【C++基础】std::string详解

std::string 是 C++ 标准库提供的用于处理字符串的类。它在 头文件中定义。std::string 提供了一种灵活、高效的字符串表示方式,相比于 C 语言中的字符串表示(使用字符数组或指针),std::string 更易于使用,更安全,并且提供了许多便捷的操作。

2201_75772333的博客 1万+

std::string 和 std::string_view

std::string与std::string_view核心区别:string拥有内存、可修改但拷贝成本高;string_view只是视图、只读但零拷贝。string适用于存储和修改字符串,而string_view最适合函数传参、只读操作等场景。关键规则:函数参数优先用string_view,存储变量必须用string。string_view能显著提升性能(不分配内存、不拷贝),但需注意其不管理内存的特性,不能用于需要修改或长期保存字符串的场景。

谢谢大家的关注和点赞!这里只有纯纯的知识干货,没有一句废话。希望能实实在在帮到大家~要是觉得有用,别忘了给我点支持哟,你 289

OPNET卫星节点仿真避坑指南:为什么你的STK轨道文件导入后位置不对?

本文深入解析OPNET卫星节点仿真中STK轨道文件导入后位置异常的常见问题,揭示坐标系差异(ECI与ECF)、时间基准不匹配等关键因素。通过修改.SA文件头标识、统一时间基准等解决方案,帮助工程师避免仿真失真,提升卫星通信系统仿真的准确性。特别适用于STK与OPNET协同工作的卫星网络仿真场景。

weixin_30335575的博客 605

C++字符串类std::string介绍

C++字符串类std::string介绍。

new9232的博客 7761

ADXL355 STM32 HAL 库 SPI 驱动实战:从零构建高精度加速度数据采集系统

本文详细介绍了如何使用STM32 HAL库通过SPI接口驱动ADXL355高精度加速度计,构建稳定可靠的数据采集系统。从硬件连接到寄存器配置,再到数据采集与处理,提供了完整的实战代码和优化技巧,特别适合工业级振动监测等应用场景。

weixin_28738397的博客 330

std::string

拼接是指将多个 string_literals 连接成一个更长的 string_literal 的过程,不同的编程语言可能有不同的语法和规则。注意,这里的 "String"s 是一个 std::string 类型的 string_literal,因为它使用了 s 后缀。s 后缀是一个用户自定义的字面量 (user-defined literal),它可以将一个 const char* 类型的 string_literal 转换为一个 std::string 类型的 string_literal。

weixin_62486437的博客 2267

Aspen Plus下载教程Aspen Plus V14 保姆级安装步骤(附安装包)

26、在WlmAdmin界面中,依次点击【Subnet Servers】、【admin】、【Add Feature】、【From a File】、【To Server and its File】。35、在产品选择页面,勾选需要安装的所有产品(重要:不要勾选【Aspen Online(Plant Data)】),然后点击【File Location】。回到桌面,点击任务栏的【开始菜单】,在【所有应用】中找到【Aspen Plus V14】软件图标,将其拖到桌面上创建快捷方式。9、这里可以更改软件的安装位置。

ps_xiaowang的博客 1万+

vscode中使用PlatformIO创建工程加载慢

解决使用VSCODE+PlatformIO中,第一次新建工程一直加载的问题

Reasally的博客 4991

C++中std::string和std::string_view使用详解和示例

是 C++ 标准库提供的字符串类,封装了动态管理的字符数组,功能比传统的 C 风格字符串(char*)更强大、安全、易用。<string>std是一个非拥有型的只读字符串引用,不分配内存、不复制数据,适用于传参和高效处理子串。功能需求建议使用动态字符串、读写操作只读子串、传参跨平台 Unicode 处理utf8cpp或ICUUTF-16 / UTF-32 字符。

qq_36812406的博客 1353

普通人如何上岸华为OD-面试总结

总共有3道算法题,100分值的两道,200分值的一道,不同的毕业院校和专业,通过机试的分值不一样,最少需要150分通过,提前和hr联系,了解自己需要多少分通过。重中之重:哪怕你是背的题库,也请你一定不要直接抄原来的,最好是变更下方法名,否则会判定你重复率过高,从而失去后面的面试机会(实在是不会做再用此方法,凑分数所用,面试官能看到你的代码,会影响你的面试评价)本人女,所以还问道了婚育计划,有对象这点可以说,没有问题,但是如果可以的话,生孩子的时间,可以给hr说这几年不考虑。如果说没有难题,直接就挂了。

weixin_47767264的博客 5479

char * 和 std::string

实例代码如下图所示,s1 和 s2 均是常量字符串,字符串常量保存在只读数据区,是只读的,不能写,代码中注释的那两行代码会导致段错误。s3 是字符数组,字符数组是可以修改的,std::string 类型的字符串也是可以修改的。代码运行之后,可以看到 s1 和 s2 是常量字符串,这两个指针指向的地址也是相同的。从 s1,s2 的地址和 s3,s4 的地址对比可以看出,s3 和 s4 的地址相距比较近,和 s1、s2 的地址相距比较远。

weixin_38184628的博客 1706

【TCAX相关】Python 官方手册下载页面(中文+英文)

Python 官方手册下载页面(中文+英文) 中文: https://docs.python.org/zh-cn/3.8/archives/ https://docs.python.org/zh-cn/3.6/archives/ 英文: https://www.python.org/doc/versions/ https://docs.python.org/3/archives/ https://www.python.org/ftp/python/doc/ ...

Seekladoom的博客 1019

XCKU060光纤卡学习资料保存:基于kintex UltraScale XCKU060的双路QSFP+光纤PCIe 卡

基于kintex UltraScale XCKU060的双路QSFP+光纤PCIe 卡 一、板卡概述 本板卡系我司自主研发,基于XilinxUltraScaleKintex系列FPGAXCKU060-FFVA1156-2-I架构,支持PCIEGen3x8模式的高速信号处理板卡,搭配两路40GQSFP+接口,两组64-bitDDR4,每组容量8Gbyte,可稳定运行在2400MT/s。板卡具有自控上电顺序,BP...

3077

std string详解

std string详解

qq_44894420的博客 4272

中兴OLT配置实战:从零开始,手把手教你完成一个HGU的完整业务开通(含DBA模板、限速与远程升级)

本文详细介绍了中兴OLT配置实战,从零开始手把手教你完成HGU的完整业务开通,包括DBA模板设计、限速与远程升级等关键步骤。通过实际案例和详细命令,帮助工程师快速掌握GPON网络配置技巧,提升运维效率。

weixin_30599769的博客 358

std::string和std::string_view区别

文章摘要: std::string和std::string_view的核心区别在于存储方式和生命周期管理。std::string拥有独立内存(堆分配),可修改且安全;std::string_view仅作为轻量级只读视图(16字节),不管理内存但需注意原始数据生命周期。性能上,string_view零拷贝,适合参数传递和解析;string适合长期存储。ESP32开发建议:函数参数优先用string_view减少拷贝,持久化数据用string防悬空。典型场景如日志用string,HTTP头解析用string_v

qq_31385559的博客 589

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

在C++中std::string 和string有啥区别呀?

推荐使用:明确且安全,避免命名冲突。谨慎使用:虽然代码更简洁,但可能导致命名冲突,特别是在大型项目中。使用:只引入需要的类型,避免命名冲突。后面我又看见既然string是用std::string来的,那么有没有str::int函数?AI告诉我不存在str::int,因为C++中直接有int类型.

printfLILEI的博客 970

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

std::string的用法

本文主要针对那些有C语言背景知识,而现在开始使用C++语言编程的程序员。事实上,C++继承了大多数C语言的功能,但有些方面还是不得不要留意的,如new和delete取代了malloc和free,且C++还使用了STL容器类来静态或动态地分配数组。本文中要讲的是用std::string来取代char*,将会演示C风格数组带来的一系列问题,及如何使用std::string来避免这些问题。避免“病态”的

菜鸟的专栏 2万+

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

Qt中QString和std::string的截取函数详解

Qt中QString和std::string的截取函数详解

qq_46017342的博客 5071

char[]与std::string的联系

C++中的C风格字符串(char[])和std::string分别代表传统与现代的字符串处理方式。C风格字符串是固定长度的字符数组,依赖空字符结尾,需要手动管理内存和边界检查,易引发缓冲区溢出等问题。std::string作为标准库类,封装了动态内存管理,提供安全的边界检查和便捷的操作方法,但会带来微小性能开销。 适用场景对比:C风格字符串适合与C API交互、性能敏感代码和固定长度文本;std::string更适合动态文本处理、复杂字符串操作和跨模块数据传输。现代C++开发中应优先使用std::strin

qq_39980997的博客 816

c++ int64 转 string_C++ std::wstring 互转 std::string

1、std::wstring 转 std::stringstring WstringToString(const std::wstring wstr){#if 1 std::string result; int len = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL); ...

weixin_34579167的博客 762
上一篇: fatal error C1001: 编译器中发生内部错误。
下一篇: winsock的阻塞和非阻塞通信模型
凭谁问
博客等级 码龄15年 178粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址