主頁 > 軟體設計 > 【C++入門】C++ string類

【C++入門】C++ string類

2021-02-15 12:15:43 軟體設計

C++string類

在這里插入圖片描述

文章目錄

  • C++string類
    • 一、string基本概念
    • 二、string初始化
      • (1)建構式
      • (2)默認建構式
      • (3)復制建構式
    • 三、string的輸入輸出
      • (1)輸入
      • (2)輸出
    • 四、string的賦值
      • (1)用 = 賦值
      • (2)用 assign 成員函式復制
    • 五、string的連接
      • (1)用 + 、+=運算子連接字串
      • (2)用成員函式 append 連接字串
    • 六、string元素存取 (訪問)
      • (1)下標運算子 [ ]
      • (2)成員函式at()
    • 七、string大小和容量
    • 八、string的比較
      • (1)`>` 、 `<` 、 `==` 、 `>=` 、`<=`、 `!=` 等比較運算子
      • (2)compare()函式
    • 九、string的查找
      • (1)find ()函式和 rfind()函式
      • (2)find_first_of ()函式和 find_last_of ()函式
      • (3)find_first_not_of ()函式和find_last_not_of ()
      • (4)查找代碼示例
    • 十、string內容的修改和替換
      • (1)string類的替換函式
      • (2)string類的插入函式
      • (3)string類的洗掉函式
    • 十一、常用操作
      • string的子串
      • string的交換
    • 十二、string類的迭代器處理
      • (1)正向迭代
      • (2)反向迭代
    • 十三、字串流處理
      • (1)字串流處理 - 字串輸入流 istringstream
      • (2)字串流處理 - 字串輸出流 istringstream
    • 十四、轉換成C語言式char *字串
      • (1)成員函式 c_str()
      • (2)成員函式data()
      • (3)成員函式copy()

一、string基本概念

  • string 類是模板類:

    typedef basic_string<char> string;
    
  • 字串類模板 (basic string)
    標準庫字串功能的基礎是 basic string,該類模板提供了許多成員和函式, 與標準容器 類似,該類模板的宣告如下:

    template <class Ch, class Tr = char_traits<Ch>, class A = allocator<Ch>>
    class std::basic_string
    {
    public:}
    

    在上述模板宣告中,第一個引數(class Ch)是說明單個字符(Ch)所屬型別(class);第二個引數 (class Tr = char traits < Ch > ) 是特性類別, 用以提供字串類別中的所有字符 核心操作, 該特性類別規定了 “復制字符” 或 “比較字符” 的做法; 如果不指定該特性類別,系統會根據現有的字符型別采用默認的特性類別, 第三個引數帶有默認值(class A = allocator < Ch > ), 用以定義字串類別所采用的記憶體模式, 通常設定為 “默認記憶體模型 al- locator”, 該模板及其相關功能都定義在名稱空間 std 中, 由頭檔案 < string > 給出,

  • string 類的所有成員函式

函 數 名 稱效 果
建構式產生或復制字串
解構式銷毀字串
= , assign賦以新值
Swap交換兩個字串的內容
+ = , append(), push_back()添加字符
insert()插入字符
erase()洗掉字符
clear()移除全部字符
resize()改變字符數量
replace()替換字符
串聯字串
== ,!= ,<,<=,>,>=,compare()比較字串內容
size(), length()回傳字符數量
max_size()回傳字符的最大可能個數
empty()判斷字串是否為空
capacity()回傳重新分配之前的字符容量
reserve()保留記憶體以存盤一定數量的字符
[], at()存取單一字符
>> , getline()從 stream 中讀取某值
<<將值寫入 stream
copy()將內容復制為一個 C - string
c_str()將內容以 C - string 形式回傳
data()將內容以字符陣列形式回傳
substr()回傳子字串
find()搜尋某子字串或字符
begin(), end()提供正向迭代器支持
rbegin(), rend()提供逆向迭代器支持
get_allocator()回傳配置器

二、string初始化

(1)建構式

  • 生成字串 str 的復制品

    • 函式說明

      string s(str) //str是string型別量
      
    • 函式示例

      string str="hello world";
      string s(str);
      cout<<s;
      

      輸出:
      hello world

  • 將字串 str 中始于 stridx 的部分作為建構式的初值

    • 函式說明

      string s(str, stridx) // str是string型別量,stridx是起始位置下標
      
    • 函式示例

      string str="hello world";
      string s(str, 6);
      cout<<s;
      

      輸出:
      world

  • 將字串 str 中始于 strbegin、長度為 strlen 的部分作為字串初值

    • 函式說明

      string s(str, strbegin, strlen) //str是字串,strbegin是起始位置下標,strlen是字串長度
      
    • 函式示例

      char *str = "hello world";
      string s(str, 2, 3);
      cout << s;
      

      輸出:
      llo

  • 以 C_string 型別 cstr 作為字串 s 的初值

    • 函式說明

      string s(cstr) //cstr是字符陣列或字串常量
      
    • 函式示例

      char *str = "hello world";
      string s(str);
      cout << s;
      

      輸出:
      hello world

  • 以 C_string 型別 cstr 的前 char_len 個字串作為字串 s 的初值

    • 函式說明
      string s (cstr, char_len) //cstr是字符陣列或字串常量,char_len是長度
      
    • 函式示例
      char str[] = "hello world";
      string s(str, 6);
      cout << s;
      

      輸出
      hello

  • 生成一個字串, 包含 num 個 c 字符

    • 函式說明
      string s (num, c) //num是int型變數,c是字符
      
    • 函式示例
      string s(3, '6');
      cout << s
      

      輸出:
      666

  • 以區間 [beg, end] 內的字符作為字串 s 的初值

    • 函式說明
      string s ( beg, end) //beg,end均為迭代器
      
    • 函式示例
      string str = "hello world";
      string::iterator i=str.begin();
      string s(i,i+3);
      cout << s;
      

      輸出:
      hel

(2)默認建構式

  • 生成空字串

    string s;
    

    若不提供分配器,則從默認構造的實體獲得分配器,

(3)復制建構式

當構造的string太長而無法表達時會拋出length_error例外

string s2 = "hello";

三、string的輸入輸出

(1)輸入

  • string 支持流讀取運算子

    string類多載運算子operator>>用于輸入;
    cin>>s; 讀入s,遇到空格或回車停止,無論原先s是什么內容都會被新讀入的資料替代

    string s;
    getline(cin ,s);
    
  • string 支持getline函式

    函式getline(istream &in,string &s);用于從輸入流in中讀取字串到s中,以換行符’\n’分開,

    string stringObject;
    cin >> stringObject;
    

(2)輸出

多載運算子operator<<用于輸出操作,

cout << s;

四、string的賦值

(1)用 = 賦值

string &operator=(const string &s);把字串s賦給當前字串

string s = "hello"
string s1;
s1 = s;

(2)用 assign 成員函式復制

  • 函式示例

    • 用 assign 成員函式復制

      string s1("cat"), s3;
      s3.assign(s1);
      
    • 用 assign 成員函式部分復制

      string s1("catpig"), s3;
      s3.assign(s1, 1, 3);
      

      從s1 中下標為1的字符開始復制3個字符給s3

  • 函式說明

    • 用c型別字串s賦值

      string &assign(const char *s);
      
    • 用c字串s開始的n個字符賦值

      string &assign(const char *s,int n);
      
    • 把字串s賦給當前字串

      string &assign(const string &s);
      
    • 用n個字符c賦值給當前字串

      string &assign(int n,char c);
      
    • 把字串s中從start開始的n個字符賦給當前字串

      string &assign(const string &s,int start,int n);
      
    • 把first和last迭代器之間的部分賦給字串

      string &assign(const_iterator first,const_itertor last);
      

五、string的連接

(1)用 + 、+=運算子連接字串

  • 多載說明

    string &operator+=(const string &s);
    

    把字串s連接到當前字串的結尾

  • 運用舉例:

    string s1("good "), s2("morning! ");
    s1 += s2;
    cout << s1;
    

    輸出:
    good morning!

(2)用成員函式 append 連接字串

  • 函式示例

    string s1("good "), s2("morning! ");
    s1.append(s2);
    cout << s1;
    s2.append(s1, 3, s1.size()); //s1.size(),s1字符數
    cout << s2;
    

    下標為3開始,s1.size()個字符,如果字串內沒有足夠字符,則復制到字串最后一個字符

  • 函式說明

    • 把c型別字串s連接到當前字串結尾
      string &append(const char *s);
      
    • 把c型別字串s的前n個字符連接到當前字串結尾
      string &append(const char *s,int n);
      
    • 同operator+=()
      string &append(const string &s);   
      
    • 把字串s中從pos開始的n個字符連接到當前字串的結尾
      string &append(const string &s,int pos,int n);
      
    • 在當前字串結尾添加n個字符c
      string &append(int n,char c);
      
    • 把迭代器first和last之間的部分連接到當前字串的結尾
      string &append(const_iterator first,const_iterator last);
      

六、string元素存取 (訪問)

(1)下標運算子 [ ]

  • 運算子說明

    下標運算子 []在使用時不檢查索引的有效性,如果下標超出字符的長度范圍,會導致未定義行為;對于常量字串,使用下標運算子時,字串的最后字符 (即 '\0') 是有效的, 對應 string 型別物件 (常量型) 最后一個字符的下標是有效的,呼叫回傳字符 '\0'

  • 運算子示例

    string s1("Hello");
    s1[3] = 'a';
    

(2)成員函式at()

  • 函式說明

    函式 at() 在使用時會檢查下標是否有效, 如果給定的下標超出字符的長度范圍, 系統 會拋出 out of range 例外,

  • 函式示例

    string s1("Hello");
    for(int i=0;i<s1.length();i++)
    	cout << s1.at(i) << endl;
    

    逐個訪問string物件中的字符

七、string大小和容量

  • size()和 length()

    int size()const; 
    
    int length()const;
    

    size()和 length(), 這兩個函式會回傳 string 型別物件中的字符個數,且它們的執行效果相同,

  • max_size()

    int max_size()const; 
    

    max_size()函式回傳 string 型別物件最多包含的字符數, 一旦程式使用長度超過 max_size()的 string 操作, 編譯器會拋出 length_error 例外,

  • capacity()

    int capacity()const;
    

    該函式回傳在重新分配記憶體之前, string 型別物件所能包含的最大字符數,

  • reserve()

    呼叫該函式可以為 string 型別物件重新分配 記憶體, 重新分配的大小由其引數決定, reserve() 的默認引數為 0,

  • empty()

    bool empty()const;
    

    當前字串是否為空

  • resize

    void resize(int len,char c);
    

    把字串當前大小置為len,并用字符c填充不足的部分

八、string的比較

(1)==>=<=!= 等比較運算子

  • 比較兩個字串是否相等

    bool operator==(const string &s1,const string &s2)const;
    

    運算子">","<",">=","<=","!="均被多載用于字串的比較;

(2)compare()函式

compare函式在>時回傳1,<時回傳-1,==時回傳0

  • 比較當前字串和s的大小

    int compare(const string &s) const;
    
  • 比較當前字串從pos開始的n個字符組成的字串與s的大小

    int compare(int pos, int n,const string &s)const;
    
  • 比較當前字串從pos開始的n個字符組成的字串與s中pos2開始的n2個字符組成的字串的大小

    int compare(int pos, int n,const string &s,int pos2,int n2)const;
    
  • 與字符陣列的比較

    int compare(const char *s) const;
    int compare(int pos, int n,const char *s) const;
    int compare(int pos, int n,const char *s, int pos2) const;
    

九、string的查找

(1)find ()函式和 rfind()函式

  • find()

    • 從pos開始查找字符c在當前字串的位置

      int find(char c, int pos = 0) const;
      
    • 從pos開始查找字串s在當前串中的位置

      int find(const char *s, int pos = 0) const;
      
    • 從pos開始查找字串s中前n個字符在當前串中的位置

      int find(const char *s, int pos, int n) const;
      
    • 從pos開始查找字串s在當前串中的位置

      int find(const string &s, int pos = 0) const;
      
  • rfind()

    • 回傳最后一個與str中的某個字符匹配的字符,從index開始查找,如果沒找到就回傳string::npos

      size_type rfind( const basic_string &str, size_type index );
      
      size_type rfind( const char *str, size_type index );
      
    • 回傳最后一個與str中的某個字符匹配的字符,從index開始查找,最多查找num個字符,如果沒找到就回傳string::npos

      size_type rfind( const char *str, size_type index, size_type num );
      
    • 回傳最后一個與ch匹配的字符,從index開始查找,如果沒找到就回傳string::npos

      size_type rfind( char ch, size_type index );
      

(2)find_first_of ()函式和 find_last_of ()函式

  • find_first_of ()

    • 查找在字串中第一個與str中的某個字符匹配的字符,回傳它的位置,搜索從index開始,如果沒找到就回傳string::npos

      size_type find_first_of( const basic_string &str, size_type index = 0 );
      
      size_type find_first_of( const char *str, size_type index = 0 );
      
    • 查找在字串中第一個與str中的某個字符匹配的字符,回傳它的位置,搜索從index開始,最多搜索num個字符,如果沒找到就回傳string::npos

      size_type find_first_of( const char *str, size_type index, size_type num );
      
    • 查找在字串中第一個與ch匹配的字符,回傳它的位置,搜索從index開始

      size_type find_first_of( char ch, size_type index = 0 );
      
  • find_last_of ()

    • 在字串中查找最后一個與str中的某個字符匹配的字符,回傳它的位置,搜索從index開始,如果沒找到就回傳string::nops

      size_type find_last_of( const basic_string &str, size_type index = npos );
      
      size_type find_last_of( const char *str, size_type index = npos );
      
    • 在字串中查找最后一個與str中的某個字符匹配的字符,回傳它的位置,搜索從index開始,最多搜索num個字符,如果沒找到就回傳string::nops

      size_type find_last_of( const char *str, size_type index, size_type num );
      
    • 在字串中查找最后一個與ch匹配的字符,回傳它的位置,搜索從index開始,如果沒找到就回傳string::nops

      size_type find_last_of( char ch, size_type index = npos );
      

(3)find_first_not_of ()函式和find_last_not_of ()

  • find_first_not_of ()

    • 在字串中查找第一個與str中的字符都不匹配的字符,回傳它的位置,搜索從index開始,如果沒找到就回傳string::nops

      size_type find_first_not_of( const basic_string &str, size_type index = 0 );
      
      size_type find_first_not_of( const char *str, size_type index = 0 );
      
    • 在字串中查找第一個與str中的字符都不匹配的字符,回傳它的位置,搜索從index開始,最多查找num個字符,如果沒找到就回傳string::nops

      size_type find_first_not_of( const char *str, size_type index, size_type num );
      
    • 在字串中查找第一個與ch不匹配的字符,回傳它的位置,搜索從index開始,如果沒找到就回傳string::nops

      size_type find_first_not_of( char ch, size_type index = 0 );
      
  • find_last_not_of ()

    • 在字串中查找最后一個與str中的字符都不匹配的字符,回傳它的位置,搜索從index開始,如果沒找到就回傳string::nops

      size_type find_last_not_of( const basic_string &str, size_type index = npos );
      
      size_type find_last_not_of( const char *str, size_type index = npos);
      
    • 在字串中查找最后一個與str中的字符都不匹配的字符,回傳它的位置,搜索從index開始,最多查找num個字符如果沒找到就回傳string::nops

      size_type find_last_not_of( const char *str, size_type index, size_type num );
      
    • 在字串中查找最后一個與ch不匹配的字符,回傳它的位置,搜索從index開始,如果沒找到就回傳string::nops

      size_type find_last_not_of( char ch, size_type index = npos );
      

(4)查找代碼示例

string s1("hello worlld");
cout << s1.find("ll") << endl;
cout << s1.find("abc") << endl;
cout << s1.rfind("ll") << endl;
cout << s1.rfind("abc") << endl;
cout << s1.find_first_of("abcde") << endl;
cout << s1.find_first_of("abc") << endl;
cout << s1.find_last_of("abcde") << endl;
cout << s1.find_last_of("abc") << endl;
cout << s1.find_first_not_of("abcde") << endl;
cout << s1.find_first_not_of("hello world") << endl;
cout << s1.find_last_not_of("abcde") << endl;
cout << s1.find_last_not_of("hello world") << endl;

輸出:
2
4294967295
9
4294967295
1
4294967295
11
4294967295
0
4294967295
10
4294967295

十、string內容的修改和替換

(1)string類的替換函式

  • replace()函式說明

    • 用str中的num個字符替換本字串中的字符,從index開始

      basic_string &replace( size_type index, size_type num, const basic_string &str );
      
    • 用str中的num2個字符(從index2開始)替換本字串中的字符,從index1開始,最多num1個字符

      basic_string &replace( size_type index1, size_type num1, const basic_string &str, size_type index2,size_type num2 );
      
    • 用str中的num個字符(從index開始)替換本字串中的字符

      basic_string &replace( size_type index, size_type num, const char *str );
      
    • 用str中的num2個字符(從index2開始)替換本字串中的字符,從index1開始,num1個字符

      basic_string &replace( size_type index, size_type num1, const char *str, size_type num2 );
      
    • 用num2個ch字符替換本字串中的字符,從index開始

      basic_string &replace( size_type index, size_type num1, size_type num2, char ch );
      
    • 用str中的字符替換本字串中的字符,迭代器start和end指示范圍

      basic_string &replace( iterator start, iterator end, const basic_string &str );
      
      basic_string &replace( iterator start, iterator end, const char *str );
      
    • 用str中的num個字符替換本字串中的內容,迭代器start和end指示范圍

      basic_string &replace( iterator start, iterator end, const char *str, size_type num );
      
    • 用num個ch字符替換本字串中的內容,迭代器start和end指示范圍

      basic_string &replace( iterator start, iterator end, size_type num, char ch );
      
  • 函式示例

    string s1("hello world");
    s1.replace(2,3, "haha");
    cout << s1;
    //將s1中下標2 開始的3個字符換成“haha”
    

    輸出:
    hehaha world

(2)string類的插入函式

  • insert()函式說明

    • 在迭代器i表示的位置前面插入一個字符ch

      iterator insert( iterator i, const char &ch );
      
    • 在字串的位置index插入字串str

      basic_string &insert( size_type index, const basic_string &str );
      
      basic_string &insert( size_type index, const char *str );
      
    • 在字串的位置index插入字串str的子串(從index2開始,長num個字符)

      basic_string &insert( size_type index1, const basic_string &str, size_type index2, size_type num );
      
    • 在字串的位置index插入字串str的num個字符

      basic_string &insert( size_type index, const char *str, size_type num );
      
    • 在字串的位置index插入num個字符ch的拷貝

      basic_string &insert( size_type index, size_type num, char ch );
      
    • 在迭代器i表示的位置前面插入num個字符ch的拷貝

      void insert( iterator i, size_type num, const char &ch );
      
    • 在迭代器i表示的位置前面插入一段字符,從start開始,以end結束

      void insert( iterator i, iterator start, iterator end );
      
  • 函式示例

    string s1("hello world");
    string s2("show insert");
    s1.insert(5, s2) // 將s2插入s1下標5的位置
        cout
        << s1 << endl;
    s1.insert(2, s2, 5, 3);
    //將s2中下標5開始的3個字符插入s1下標2的位置
    cout << s1 << endl;
    

    輸出:
    helloshow insert world
    heinslloshow insert world

(3)string類的洗掉函式

  • erase()函式說明

    • 洗掉pos指向的字符, 回傳指向下一個字符的迭代器

      iterator erase( iterator pos );
      
    • 洗掉從start到end的所有字符, 回傳一個迭代器,指向被洗掉的最后一個字符的下一個位置

      iterator erase( iterator start, iterator end );
      
    • 洗掉從index索引開始的num個字符, 回傳*this

      basic_string &erase( size_type index = 0, size_type num = npos );
      
  • 函式示例

    string s1("hello worlld");
    s1.erase(5);
    cout << s1;
    cout << s1.length();
    cout << s1.size();
    // 去掉下標 5 及之后的字符
    

    輸出:
    hello55

十一、常用操作

string的子串

  • substr函式

    string substr(int pos = 0,int n = npos) const;
    

    回傳pos開始的n個字符組成的字串

  • 函式示例

    string s1("hello world"), s2;
    s2 = s1.substr(4,5); // 下標4開始5個字符
    cout << s2 << endl;
    

    輸出:
    o wor

string的交換

  • swap函式

    void swap(string &s2);
    

    交換當前字串與s2的值

  • 函式示例

    string s1("hello world"), s2("really");
    s1.swap(s2); 
    cout << s1 << endl;
    cout << s2 << endl;
    

    輸出:
    really
    hello world

十二、string類的迭代器處理

string類提供了向前和向后遍歷的迭代器iterator,迭代器提供了訪問各個字符的語法,類似于指標操作,迭代器不檢查范圍,
string::iteratorstring::const_iterator宣告迭代器變數,const_iterator不允許改變迭代的內容,

(1)正向迭代

  • begin()

    onst_iterator begin()const;
    iterator begin(); //回傳string的起始位置
    
  • end()

    const_iterator end()const;
    iterator end(); //回傳string的最后一個字符后面的位置
    

(2)反向迭代

(反向迭代器自增后指向前一個值)

  • rbegin()

     const_iterator rbegin()const;
     iterator rbegin();  //回傳string的最后一個字符的位置
    
  • rend()

     const_iterator rend()const;
     iterator rend(); //回傳string第一個字符位置的前面
    

十三、字串流處理

除了標準流和檔案流輸入輸出外,還可以從string進行 輸入輸出;
類似 istream和osteram進行標準流輸入輸出,我們用 istringstream 和 ostringstream進行字串上的輸入 輸出,也稱為記憶體輸入輸出,
頭檔案:#include <sstream>

(1)字串流處理 - 字串輸入流 istringstream

string input("Input test 123 4.7 A"); 
istringstream inputString(input); 
string string1, string2; 
int i; 
double d; 
char c; 
inputString >> string1 >> string2 >> i >> d >> c; 
cout << string1 << endl << string2 << endl; 
cout << i << endl << d << endl << c <<endl; 
long L; 
if(inputString >> L) cout << "long\n"; 
else cout << "empty\n"; 

輸出: Input test 123
4.7 A empty

(2)字串流處理 - 字串輸出流 istringstream

ostringstream outputString; 
int a = 10; 
outputString << "This " << a << "ok" << endl; 
cout << outputString.str(); 

輸出:
This 10ok

十四、轉換成C語言式char *字串

(1)成員函式 c_str()

  • 函式說明

    const char *c_str();
    

    c_str()函式回傳一個指向正規C字串的指標, 內容與本字串相同.

  • 函式示例

    string s1("hello world");
    printf("%s\n", s1.c_str());
    

    輸出:
    hello world

(2)成員函式data()

  • 函式說明

    const char *data();
    

    data()函式回傳指向自己的第一個字符的指標.

  • 函式示例

    string s1("hello world");
    const char *p1 = s1.data();
    for (int i = 0; i < s1.length(); i++)
        printf("%c", *(p1 + i));
    //s1.data() 回傳一個char * 型別的字串,對s1 的修改可能會使p1出錯
    

    輸出:
    hello world

(3)成員函式copy()

  • 函式說明

    size_type copy( char *str, size_type num, size_type index );
    

    copy()函式拷貝自己的num個字符到str中(從索引index開始),回傳值是拷貝的字符數

  • 函式示例

    string s1("hello world");
    int len = s1.length();
    char *p2 = new char[len + 1];
    s1.copy(p2, 5, 0);
    p2[5] = 0;
    cout << p2 << endl;
    // s1.copy(p2,5,0) 從s1的下標0的字符開始制作一個最長5個字符長度的字串副本并將其賦值給p2,回傳值表明實際復制字串的長度,
    

    輸出:
    hello

【知識索引】【C++入門】

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/259774.html

標籤:其他

上一篇:Codeforces Round #701 (Div. 2) A ~ F ,6題全,超高質量良心題解【每日億題】2021/2/13

下一篇:Android——Lambda

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:20:25 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:20:17 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:20:10 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:19:44 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:19:07 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:18:57 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:18:49 more
  • 05單件模式

    #經典的單件模式 public class Singleton { private static Singleton uniqueInstance; //一個靜態變數持有Singleton類的唯一實體。 // 其他有用的實體變數寫在這里 //構造器宣告為私有,只有Singleton可以實體化這個類! ......

    uj5u.com 2023-04-19 08:42:51 more
  • 【架構與設計】常見微服務分層架構的區別和落地實踐

    軟體工程的方方面面都遵循一個最基本的道理:沒有銀彈,架構分層模型更是如此,每一種都有各自優缺點,所以請根據不同的業務場景,并遵循簡單、可演進這兩個重要的架構原則選擇合適的架構分層模型即可。 ......

    uj5u.com 2023-04-19 08:42:41 more