主頁 > 軟體設計 > C++STL詳解(一)—— string類

C++STL詳解(一)—— string類

2021-06-16 08:17:18 軟體設計

文章目錄

  • C++STL詳解(一)—— sring類
  • 一、string的定義方式
  • 二、string的插入
  • 三、string的拼接
  • 四、string的洗掉
  • 五、string的查找
  • 六、string的比較
  • 七、string的替換
  • 八、string的交換
  • 九、string的大小和容量
  • 十、string中元素的訪問
  • 十一、string中運算子的使用
  • 十二、string中與迭代器相關的函式
  • 十三、string與字串之間的轉換
  • 十四、string中子字串的提取
  • 十五、string中的getline函式

C++STL詳解(一)—— sring類

本次內容大綱:
在這里插入圖片描述

一、string的定義方式

string類實作了多個建構式的多載,常用的建構式如下:

string();  //構造一個空字串

string(const char* s);  //復制s所指的字符序列

string(const char* s, size_t n);  //復制s所指字符序列的前n個字符

string(size_t n, char c);  //生成n個c字符的字串

string(const string& str);  //生成str的復制品

string(const string& str, size_t pos, size_t len = npos);  //復制str中從字符位置pos開始并跨越len個字符的部分

使用示例:

string s1;                     //構造空字串
string s2("hello string");     //復制"hello string"
string s3("hello string", 3);  //復制"hello string"的前3個字符
string s4(10, 's');            //生成10個's'字符的字串
string s5(s2);                 //生成s2的復制品
string s6(s2, 0, 4);           //復制s2中從字符位置0開始并跨越4個字符的部分

二、string的插入

1、使用push_back進行尾插

void push_back (char c);

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	s.push_back('C');
	s.push_back('S');
	s.push_back('D');
	s.push_back('N');
	cout << s << endl; //CSDN
	return 0;
}

2、使用insert插入

string& insert (size_t pos, const string& str);
string& insert (size_t pos, const char* s);
iterator insert (iterator p, char c);

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("C"); //C

	//insert(pos, str)在pos位置插入字串str
	s.insert(1, "S"); //CS

	//insert(pos, string)在pos位置插入string物件
	string t("D");
	s.insert(2, t); //CSD

	//insert(pos, char)在pos位置插入字符char
	s.insert(s.end(), 'N'); //CSDN
	
	cout << s << endl; //CSDN
	return 0;
}

三、string的拼接

使用append函式完成string的拼接:

string& append (const string& str);
string& append (const char* s);
string& append (size_t n, char c);

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1("I");
	string s2(" like");

	//append(string)完成兩個string物件的拼接
	s1.append(s2); //I like

	//append(str)完成string物件和字串str的拼接
	s1.append(" C++"); //I like C++

	//append(n, char)將n個字符char拼接到string物件后面
	s1.append(3, '!'); //I like C++!!!
	
	cout << s1 << endl; //I like C++!!!
	return 0;
}

四、string的洗掉

1、使用pop_back進行尾刪

void pop_back();

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("C++");
	s.pop_back();
	s.pop_back();
	cout << s << endl; //C
	return 0;
}

2、使用erase洗掉

string& erase (size_t pos = 0, size_t len = npos);
iterator erase (iterator p);
iterator erase (iterator first, iterator last);

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("I like C++!!!");

	//erase(pos, n)洗掉pos位置開始的n個字符
	s.erase(8, 5); //I like C

	//erase(pos)洗掉pos位置的字符
	s.erase(s.end()-1); //I like

	//erase(pos1, pos2)洗掉[pos1pos2)上所有字符
	s.erase(s.begin() + 1, s.end()); //I

	cout << s << endl; //I
	return 0;
}

五、string的查找

1、使用find函式正向搜索第一個匹配項

size_t find (const string& str, size_t pos = 0) const;
size_t find (const char* s, size_t pos = 0) const;
size_t find (char c, size_t pos = 0) const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1("http://www.cplusplus.com/reference/string/string/find/");

	//find(string)正向搜索與string物件所匹配的第一個位置
	string s2("www");
	size_t pos1 = s1.find(s2);
	cout << pos1 << endl; //7

	//find(str)正向搜索與字串str所匹配的第一個位置
	char str[] = "cplusplus.com";
	size_t pos2 = s1.find(str);
	cout << pos2 << endl;  //11

	//find(char)正向搜索與字符char所匹配的第一個位置
	size_t pos3 = s1.find(':');
	cout << pos3 << endl; //4
	return 0;
}

2、使用rfind函式反向搜索第一個匹配項

size_t rfind (const string& str, size_t pos = npos) const;
size_t rfind (const char* s, size_t pos = npos) const;
size_t rfind (char c, size_t pos = npos) const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1("http://www.cplusplus.com/reference/string/string/find/");

	//rfind(string)反向搜索與string物件所匹配的第一個位置
	string s2("string");
	size_t pos1 = s1.rfind(s2);
	cout << pos1 << endl; //42

	//rfind(str)反向搜索與字串str所匹配的第一個位置
	char str[] = "reference";
	size_t pos2 = s1.rfind(str);
	cout << pos2 << endl;  //25

	//rfind(char)反向搜索與字符char所匹配的第一個位置
	size_t pos3 = s1.rfind('/');
	cout << pos3 << endl; //53
	return 0;
}

六、string的比較

使用compare函式完成比較:

int compare (const string& str) const;
int compare (size_t pos, size_t len, const string& str) const;
int compare (size_t pos, size_t len, const string& str, size_t subpos, size_t sublen) const;

比較規則:
?1、比較字串中第一個不匹配的字符值較小,或者所有比較字符都匹配,但比較字串較短,則回傳小于0的值,
?2、比較字串中第一個不匹配的字符值較大,或者所有比較字符都匹配,但比較字串較長,則回傳大于0的值,
?3、比較的兩個字串相等,則回傳0,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1("hello world");
	string s2("hello CSDN");

	//"hello world"和"hello CSDN"比較
	cout << s1.compare(s2) << endl; //1

	//"ell"和"hello CSDN"比較
	cout << s1.compare(1, 3, s2) << endl; //-1

	//"hello"和"hello"比較
	cout << s1.compare(0, 4, s2, 0, 4) << endl; //0

	return 0;
}

注意:除了支持string類之間進行比較,compare函式還支持string類和字串進行比較,

七、string的替換

使用replace函式完成string的替換:

string& replace (size_t pos, size_t len, const char* s);
string& replace (size_t pos, size_t len, size_t n, char c);

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("hello world");

	//replace(pos, len, str)將pos位置開始的len個字符替換為字串str
	s.replace(6, 4, "CSDN"); //hello CSDNd

	//replace(pos, len, n, char)將pos位置開始的len個字符替換為n個字符char
	s.replace(10, 1, 3, '!'); //hello CSDN!!!

	cout << s << endl;
	return 0;
}

八、string的交換

使用swap函式完成兩個string類的交換:

void swap (string& x, string& y);
void swap (string& str);

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1("hello");
	string s2("CSDN");
	
	//使用string類的成員函式swap交換s1和s2
	s1.swap(s2);
	cout << s1 << endl; //CSDN
	cout << s2 << endl; //hello

	//使用非成員函式swap交換s1和s2
	swap(s1, s2);
	cout << s1 << endl; //hello
	cout << s2 << endl; //CSDN
	return 0;
}

九、string的大小和容量

1、使用size函式或length函式獲取當前有效字符的個數

size_t size() const;
size_t length() const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	cout << s.size() << endl; //4
	cout << s.length() << endl; //4
	return 0;
}

2、使用max_size函式獲取string物件對多可包含的字符數

size_t max_size() const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	cout << s.max_size() << endl; //4294967294
	return 0;
}

3、使用capacity函式獲取當前物件所分配的存盤空間的大小

size_t capacity() const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	cout << s.capacity() << endl; //15
	return 0;
}

4、使用resize改變當前物件的有效字符的個數

void resize (size_t n);
void resize (size_t n, char c);

resize規則:
?1、當n大于物件當前的size時,將size擴大到n,擴大的字符為c,若c未給出,則默認為’\0’,
?2、當n小于物件當前的size時,將size縮小到n,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1("CSDN");
	//resize(n)n大于物件當前的size時,將size擴大到n,擴大的字符默認為'\0'
	s1.resize(20);
	cout << s1 << endl; //CSDN
	cout << s1.size() << endl; //20
	cout << s1.capacity() << endl; //31

	string s2("CSDN");
	//resize(n, char)n大于物件當前的size時,將size擴大到n,擴大的字符為char
	s2.resize(20, 'x');
	cout << s2 << endl; //CSDNxxxxxxxxxxxxxxxx
	cout << s2.size() << endl; //20
	cout << s2.capacity() << endl; //31

	string s3("CSDN");
	//resize(n)n小于物件當前的size時,將size縮小到n
	s3.resize(2);
	cout << s3 << endl; //CS
	cout << s3.size() << endl; //2
	cout << s3.capacity() << endl; //15
	return 0;
}

注意:若給出的n大于物件當前的capacity,則capacity也會根據自己的增長規則進行擴大,

5、使用reserve改變當前物件的容量大小

void reserve (size_t n = 0);

reserve規則:
?1、當n大于物件當前的capacity時,將capacity擴大到n或大于n,
?2、當n小于物件當前的capacity時,什么也不做,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	cout << s << endl; //CSDN
	cout << s.size() << endl; //4
	cout << s.capacity() << endl; //15

	//reverse(n)當n大于物件當前的capacity時,將當前物件的capacity擴大為n或大于n
	s.reserve(20); 
	cout << s << endl; //CDSN
	cout << s.size() << endl; //4
	cout << s.capacity() << endl; //31

	//reverse(n)當n小于物件當前的capacity時,什么也不做
	s.reserve(2);
	cout << s << endl; //CDSN
	cout << s.size() << endl; //4
	cout << s.capacity() << endl; //31
	return 0;
}

注意:此函式對字串的size沒有影響,并且無法更改其內容,

6、使用clear洗掉物件的內容,洗掉后物件變為空字串

void clear();

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");

	//clear()洗掉物件的內容,該物件將變為空字串
	s.clear();
	cout << s << endl; //空字串
	return 0;
}

7、使用empty判斷物件是否為空

bool empty() const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	cout << s.empty() << endl; //0

	//clear()洗掉物件的內容,該物件將變為空字串
	s.clear();
	cout << s.empty() << endl; //1
	return 0;
}

十、string中元素的訪問

1、[ ]+下標
?因為string類對[ ]運算子進行了多載,所以我們可以直接使用[ ]+下標訪問物件中的元素,并且該多載使用的是參考回傳,所以我們可以通過[ ]+下標修改對應位置的元素,

???char& operator[] (size_t pos);
const char& operator[] (size_t pos) const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	//[]+下標訪問物件元素
	for (size_t i = 0; i < s.size(); i++)
	{
		cout << s[i];
	}
	cout << endl;

	//[]+下標修改物件元素內容
	for (size_t i = 0; i < s.size(); i++)
	{
		s[i] = 'x';
	}
	cout << s << endl; //xxxx
	return 0;
}

2、使用at訪問物件中的元素
?因為at函式也是使用的參考回傳,所以我們也可以通過at函式修改對應位置的元素,

???char& at (size_t pos);
const char& at (size_t pos) const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	for (size_t i = 0; i < s.size(); i++)
	{
		//at(pos)訪問pos位置的元素
		cout << s.at(i);
	}
	cout << endl;

	for (size_t i = 0; i < s.size(); i++)
	{
		//at(pos)訪問pos位置的元素,并對其進行修改
		s.at(i) = 'x';
	}
	cout << s << endl; //xxxx
	return 0;
}

3、使用范圍for訪問物件中的元素
?需要特別注意的是:若是需要通過范圍for修改物件的元素,則用于接收元素的變數e的型別必須是參考型別,否則e只是物件元素的拷貝,對e的修改不會影響到物件的元素,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	//使用范圍for訪問物件元素
	for (auto e : s)
	{
		cout << e;
	}
	cout << endl; //CSDN

	//使用范圍for訪問物件元素,并對其進行修改
	for (auto& e : s) //需要修改物件的元素,e必須是參考型別
	{
		e = 'x';
	}
	cout << s << endl; //xxxx
	return 0;
}

4、使用迭代器訪問物件中的元素

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("CSDN");
	
	//使用迭代器訪問物件元素
	string::iterator it1 = s.begin();
	while (it1 != s.end())
	{
		cout << *it1;
		it1++;
	}
	cout << endl; //CSDN

	//使用迭代器訪問物件元素,并對其進行修改
	string::iterator it2 = s.begin();
	while (it2 != s.end())
	{
		*it2 += 1;
		it2++;
	}
	cout << s << endl; //DTEO
	return 0;
}

十一、string中運算子的使用

1、operator=
?string類中對=運算子進行了多載,多載后的=運算子支持string類的賦值、字串的賦值以及字符的賦值,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1;
	string s2("CSDN");

	//支持string類的賦值
	s1 = s2;
	cout << s1 << endl; //CSDN

	//支持字串的賦值
	s1 = "hello";
	cout << s1 << endl;  //hello

	//支持字符的賦值
	s1 = 'x';
	cout << s1 << endl; //x
	return 0;
}

2、operator+=
?string類中對+=運算子進行了多載,多載后的+=運算子支持string類的復合賦值、字串的復合賦值以及字符復合的賦值,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1;
	string s2("hello");

	//支持string類的復合賦值
	s1 += s2;
	cout << s1 << endl; //hello

	//支持字串的復合賦值
	s1 += " CSDN";
	cout << s1 << endl; //hello CSDN

	//支持字符的復合賦值
	s1 += '!';
	cout << s1 << endl; //hello CSDN!
	return 0;
}

3、operator+
?string類中對+運算子進行了多載,多載后的+運算子支持以下幾種型別的操作:
?string類 + string類
?string類 + 字串
?字串 + string類
?string類 + 字符
?字符 + string類
它們相加后均回傳一個string類物件,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	string s1("super");
	string s2("man");
	char str[] = "woman";
	char ch = '!';

	//string類 + string類
	s = s1 + s2;
	cout << s << endl; //superman

	//string類 + 字串
	s = s1 + str;
	cout << s << endl; //superwoman

	//字串 + string類
	s = str + s1;
	cout << s << endl; //womansuper

	//string類 + 字符
	s = s1 + ch;
	cout << s << endl; //super!
	
	//字符 + string類
	s = ch + s1;
	cout << s << endl; //!super
	return 0;
}

4、operator>> 和 operator<<
?string類中也對>>和<<運算子進行了多載,這就是為什么我們可以直接使用>>和<<對string類進行輸入和輸出的原因,

istream& operator>> (istream& is, string& str);
ostream& operator<< (ostream& os, const string& str);

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin >> s; //輸入
	cout << s << endl; //輸出
	return 0;
}

5、relational operators
?string類中還對一系列關系運算子進行了多載,它們分別是==、!=、<、<=、>、>=,多載后的關系運算子支持string類和string類之間的關系比較、string類和字串之間的關系比較、字串和string類之間的關系比較,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1("abcd");
	string s2("abde");
	cout << (s1 > s2) << endl; //0
	cout << (s1 < s2) << endl; //1
	cout << (s1 == s2) << endl; //0
	return 0;
}

注意:這些多載的關系比較運算子所比較的都是對應字符的ASCII碼值,

十二、string中與迭代器相關的函式

1、與正向迭代器相關的函式
begin函式:回傳一個指向字串第一個字符的迭代器,

函式原型:
????iterator begin();
?const_iterator begin() const;

end函式:回傳一個指向字串結束字符的迭代器,即’\0’,

函式原型:
????iterator end();
?const_iterator end() const;

使用示例:

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("hello string");

	//正向迭代器
	string::iterator it = s.begin();
	while (it != s.end())
	{
		cout << *it;
		it++;
	}
	cout << endl; //hello string

	return 0;
}

2、與反向迭代器相關的函式
rbegin函式:回傳指向字串最后一個字符的反向迭代器,

函式原型:
????reverse_iterator rbegin();
?const_reverse_iterator rbegin() const;

rend函式:回傳指向字串第一個字符前面的理論元素的反向迭代器,

函式原型:
????reverse_iterator rend();
?const_reverse_iterator rend() const;

使用示例:

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("hello string");

	//反向迭代器
	string::reverse_iterator rit = s.rbegin();
	while (rit != s.rend())
	{
		cout << *rit;
		rit++;
	}
	cout << endl; //gnirts olleh

	return 0;
}

十三、string與字串之間的轉換

1、將字串轉換為string
?將字串轉換為string很簡單,在前面講string的定義方式時就有說到,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	//方式一
	string s1("hello world");

	//方式二
	char str[] = "hello world";
	string s2(str);

	cout << s1 << endl; //hello world
	cout << s2 << endl; //hello world
	return 0;
}

2、使用c_str或data將string轉換為字串

const char* c_str() const;
const char* data() const;

區別:

  • 在C++98中,c_str()回傳 const char* 型別,回傳的字串會以空字符結尾,
  • 在C++98中,data()回傳 const char* 型別,回傳的字串不以空字符結尾,
  • 但是在C++11版本中,c_str()與data()用法相同,
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("hello world ");
	const char* str1 = s.data();
	const char* str2 = s.c_str();

	cout << str1 << endl;
	cout << str2 << endl;
	return 0;
}

十四、string中子字串的提取

1、使用substr函式提取string中的子字串

string substr (size_t pos = 0, size_t len = npos) const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1("abcdef");
	string s2;

	//substr(pos, n)提取pos位置開始的n個字符序列作為回傳值
	s2 = s1.substr(2, 4);
	cout << s2 << endl; //cdef
	return 0;
}

2、使用copy函式將string的子字串復制到字符陣列中

size_t copy (char* s, size_t len, size_t pos = 0) const;

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s("abcdef");
	char str[20];

	//copy(str, n, pos)復制pos位置開始的n個字符到str字串
	size_t length = s.copy(str, 4, 2);
	//copy函式不會在復制內容的末尾附加'\0',需要手動加
	str[length] = '\0';
	cout << str << endl; //dcef
	return 0;
}

十五、string中的getline函式

?我們知道,使用>>進行輸入操作時,當>>讀取到空格便會停止讀取,基于此,我們將不能用>>將一串含有空格的字串讀入到string物件中,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin >> s; //輸入:hello CSDN
	cout << s << endl; //輸出:hello
	return 0;
}

?這時,我們就需要用getline函式完成一串含有空格的字串的讀取操作了,

用法一:

istream& getline (istream& is, string& str);

?getline函式將從is中提取到的字符存盤到str中,直到讀取到換行符’\n’為止,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	getline(cin, s); //輸入:hello CSDN
	cout << s << endl; //輸出:hello CSDN
	return 0;
}

用法二:

istream& getline (istream& is, string& str, char delim);

?getline函式將從is中提取到的字符存盤到str中,直到讀取到分隔符delim或換行符’\n’為止,

#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	getline(cin, s, 'D'); //輸入:hello CSDN
	cout << s << endl; //輸出:hello CS
	return 0;
}

獻上完整思維導圖:
在這里插入圖片描述
感謝閱讀!

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

標籤:其他

上一篇:鴻蒙App開發(7)---Picker組件

下一篇:【期末復習】?考試月來臨!C語言復習,這一篇帶你逃離掛科區!(完結)

標籤雲
其他(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