C ++での文字列ヘッダーファイルの使用について

注:
ここで宣言するポイントが1つあります。ヘッダーファイルの文字列とstring.hは異なります。次のコードは文字列の使用例です。文字列ヘッダーファイルの下の関数で、文字列str = "abcxyz"のような値を割り当てることができます。
基本操作:
コードに示すように:
1.演算子±
を実行できます2.サイズを比較できます
3.length()/ size()
4.insert()

一般的に使用されるいくつかの操作

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

int main()
{
    
    
	string str1 = "abcxyz", str2 = "opq",str3;
	str3 = str1 + str2;
	str1.insert(str1.begin() + 3, str2.begin(), str2.end());
	cout << str1 << endl;
	cout << str3 << endl;
	if (str1 > str2)
		cout << "1" << endl;
	cout << str1.length() << "  " << str1.size() << endl;

	system("pause");
	return 0;
}

出力:
ここに画像の説明を挿入

おすすめ

転載: blog.csdn.net/qq_27538633/article/details/105962556