Some string functions: append, to_string, stoi

1 append

Append is a more convenient way to add a string after a string than push_back , similar to a string +. This is a member function of string.
Difference: append can only add character strings, and push_back can only add characters.

	string s1 = "hello";	//s1 = "hello"
	string s2 = "world";	//s2 = "world"
	string s3 = s1 + s2;	//s3 = "helloworld"

	s1.append(' ');			//Wrong! 不能用append(char)
	s1.append(" ");			//s1 = "hello "
	s1.append(s2);			//s1 = "helloworld"

2 to_string sum stoi

to_string can convert a value to a string, whether it is an int or a float.
stoi can convert a string into a numeric value.
These two are non-member functions of the non-standard library and should be used with caution.

	int a = 666;
	string get = to_string(a);	//get = "666"
	int ret = stoi(get);		//ret = 666

Guess you like

Origin blog.csdn.net/weixin_42979679/article/details/104387845