c 中string類的使用(持續更新)

2021-10-22 16:24:43 字數 2016 閱讀 2922

ps:string中雖然有push_back();

但是沒有push_front();它不能使用前面插入迭代器

1.將整形轉為string型別

#include

#include

using

namespace std;

intmain()

2.將string 轉為int型

使用stoi,atoi;

#include

#include

using

namespace std;

intmain()

#include

#include

using

namespace std;

intmain()

} cout<

return0;

}

4.使用某一模組時應將其他模組注釋掉,避免互相影響

#include

#include

using

namespace std;

intmain()

5.字串的修改

注:.使用某一模組時應將其他模組注釋掉,避免互相影響

#include

#include

using

namespace std;

intmain()

6.字串中的查詢

注:.使用某一模組時應!!將其他模組注釋掉!!,避免互相影響

#include

#include

using

namespace std;

intmain()

7.字串的比較

#include

#include

using

namespace std;

intmain()

8.關於子字串

#include

#include

using

namespace std;

intmain()

9.字串的初始化

#include

#include

using

namespace std;

intmain()

10.字串與數值轉換

//!!!字串轉數值

#include

#include

using

namespace std;

intmain()

![在這裡插入描述](

#include

#include

using

namespace std;

intmain()

;sprintf

(arr,

"%d"

,a);

cout<

sprintf

(arr,

"%lld"

,b);

cout<

sprintf

(arr,

"%f"

,c);

cout<

//注意,若想要對其做字串的=操作,只需要申請乙個string類的物件並將陣列的值賦給字串即可

c 中string類的使用

include include include using namespace std 3.1.2.1 string 建構函式 string 建立乙個空的字串 例如 string str string const string str 使用乙個string物件初始化另乙個string物件 strin...

String類常見函式的使用 持續更新

常見函式 islower char c 是否為小寫字母 isupper char c 是否為大寫字母 isdigit char c 是否為數字 isalpha char c 是否為字母 isalnum char c 是否為字母或者數字 toupper char c 字母小轉大 tolower cha...

C 的string類使用

一 string作為c 常用的乙個類,得熟悉它的一些常用的方法。在使用這個類之前,得加上標頭檔案 include include 標準的異常類的庫 二 1 獲取string的元素個數方法,還有訪問string中的每個元素的方法 void test01 string str1 hello world ...