C++ string字符串的使用和簡(jiǎn)單模擬實(shí)現(xiàn)
前言
本文講解string串的使用和一些簡(jiǎn)單的模擬實(shí)現(xiàn),內(nèi)容豐富,干貨多多!
1. string簡(jiǎn)介
C語(yǔ)言中,字符串是以'\0'結(jié)尾的一些字符的集合,為了操作方便,C標(biāo)準(zhǔn)庫(kù)中提供了一些str系列的庫(kù)函數(shù),但是這些庫(kù)函數(shù)和字符串是分離的。不符合面向?qū)ο蟪绦蛟O(shè)計(jì)的思想,而且底層空間需要用戶自己管理,如果不細(xì)心,容易訪問(wèn)越界。
所以C++標(biāo)準(zhǔn)庫(kù)以string類(lèi)來(lái)表示字符串,更加簡(jiǎn)單,方便。
- 字符串是表示字符序列的對(duì)象。
- 標(biāo)準(zhǔn)string類(lèi)通過(guò)類(lèi)似于標(biāo)準(zhǔn)字節(jié)容器的接口提供了對(duì)此類(lèi)對(duì)象的支持,但添加了專(zhuān)門(mén)設(shè)計(jì)用于操作單字節(jié)字符串的特性。
- string類(lèi)是basic_string類(lèi)模板的實(shí)例化,該模板使用char(即字節(jié))作為其字符類(lèi)型,具有默認(rèn)的char_traits和allocator類(lèi)型(有關(guān)模板的更多信息,請(qǐng)參閱basic_string)。
- 請(qǐng)注意,該類(lèi)處理字節(jié)獨(dú)立于所使用的編碼:如果用于處理多字節(jié)或變長(zhǎng)字符序列(如UTF-8),則該類(lèi)的所有成員(如length或size)及其迭代器仍將以字節(jié)(而不是實(shí)際編碼的字符)進(jìn)行操作。
2. string的使用和簡(jiǎn)單模擬實(shí)現(xiàn)
2.1 string類(lèi)的定義
string類(lèi)是本賈尼C++之父實(shí)現(xiàn)的,但是初次實(shí)現(xiàn)難免有許多不足,如接口函數(shù)過(guò)多,接口函數(shù)重載過(guò)多,導(dǎo)致string類(lèi)十分復(fù)雜。我們對(duì)string類(lèi)進(jìn)行簡(jiǎn)單的模擬實(shí)現(xiàn),不過(guò)是實(shí)現(xiàn)一些常用的接口函數(shù),主要是粗淺地了解其中的原理。
- 因?yàn)閟tring這個(gè)容器專(zhuān)門(mén)針對(duì)字符,沒(méi)有使用類(lèi)模版,所以定義和聲明需要分離,準(zhǔn)備兩個(gè)文件string.h和string.cpp。string.h存放類(lèi)的聲明,string.cpp各種類(lèi)成員函數(shù)和變量的定義。
- 為了不跟C++標(biāo)準(zhǔn)庫(kù)里面的string發(fā)生命名沖突,可以將類(lèi)放在命名空間中,并且這兩個(gè)文件可以使用同一個(gè)命名空間,編譯的過(guò)程中就會(huì)合并。
- 因?yàn)閟tring物理存儲(chǔ)空間本質(zhì)上是連續(xù)的,不是鏈表那種隨機(jī)存儲(chǔ)的。迭代器使用char*原生的字符指針就可以模擬,不過(guò)實(shí)際的string的迭代器基本是用類(lèi)封裝實(shí)現(xiàn)。
#define _CRT_SECURE_NO_WARNINGS
#pragma once
#include <iostream>
#include <assert.h>
using namespace std;
namespace Rustle
{
class string
{
public:
typedef char* iterator;
typedef const char* const_iterator;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
//構(gòu)造函數(shù)
//string();
string(const char* str = "");
//拷貝構(gòu)造函數(shù)
string(const string& s);
//賦值拷貝函數(shù)
//string& operator=(const string& s);
string& operator=(string tmp);
//析構(gòu)函數(shù)
~string();
void swap(string& s);
const char* c_str() const;
size_t size() const;
char& operator[](size_t pos);
const char& operator[](size_t pos) const;
void reserve(size_t n);
void push_back(char ch);
void append(const char* str);
string& operator+=(char ch);
string& operator+=(const char* str);
void insert(size_t pos, char ch);
void insert(size_t pos, const char* str);
void erase(size_t pos, size_t len = npos);
size_t find(char ch, size_t pos = 0);
size_t find(const char* str, size_t pos = 0);
string substr(size_t pos = 0, size_t len = npos);
bool operator<(const string& s)const;
bool operator>(const string& s)const;
bool operator<=(const string& s)const;
bool operator>=(const string& s)const;
bool operator==(const string& s)const;
bool operator!=(const string& s)const;
void clear();
private:
char* _str = nullptr;//置空
size_t _size = 0;
size_t _capacity = 0;
const static size_t npos;
};
istream& operator>>(istream& is, string& str);
ostream& operator<<(ostream& os, const string& str);
}
2.2 string(),~string()和c_str()
- 構(gòu)造函數(shù)如果使用第一種寫(xiě)法,將所有成員變量使用初始化列表進(jìn)行初始化。一般來(lái)說(shuō)是可以的,但是每一次都需要調(diào)用strlen這個(gè)庫(kù)函數(shù),會(huì)消耗時(shí)間。
- 可能有的人會(huì)用第二種寫(xiě)法,交換一下初始化列表中的順序,先將_size初始化,之后的成員變量直接使用_size就行。但是初始化列表初始化的順序跟函數(shù)中初始化列表順序無(wú)關(guān),只跟成員變量聲明的順序有關(guān)。
- 最好的解決方案就是第三種構(gòu)造函數(shù)的寫(xiě)法,先使用初始化列表進(jìn)行初始化,然后在函數(shù)內(nèi)部進(jìn)行動(dòng)態(tài)開(kāi)辟一塊與str相同大小的空間,使用strcpy拷貝str字符串的內(nèi)容,strcpy還會(huì)自動(dòng)在字符串末尾加上斜杠0。
- 需要注意的是,_size指的是字符串的大小,_capacity指的是斜杠0之前的字符個(gè)數(shù),不包含斜杠0。所以之前_str中空間大小事_size+1,給斜杠0預(yù)留一個(gè)空間。
- 析構(gòu)函數(shù)先釋放_(tái)str指向的空間,然后_str置為空指針,其他兩個(gè)成員變量置為0。
- 有些時(shí)候需要像C語(yǔ)言一樣訪問(wèn)字符串,而string是一個(gè)類(lèi)無(wú)法直接訪問(wèn),c_str函數(shù)就是解決這種問(wèn)題,這個(gè)函數(shù)可以獲取_str指針,即第一個(gè)字符的地址。
namespace Greg
{
//1.
string::string(const char* str)
:_str(new char[strlen(str) + 1])
,_size(strlen(str))
,_capacity(strlen(str))
{
assert(str);
strcpy(_str, str);
}
//2.
string::string(const char* str)
:_size(strlen(str))
,_str(new char[_size + 1])
,_capacity(_size)
{
assert(str);
strcpy(_str, str);
}
//全缺省構(gòu)造函數(shù)
string::string(const char* str)
:_size(strlen(str))
{
assert(str);
//初始化列表和函數(shù)內(nèi)部初始化混合著用
_str = new char[_size + 1];
_capacity = _size;
strcpy(_str, str);
}
string::~string()
{
delete[] _str;
_str = nullptr;
_size = _capacity = 0;
}
const char* string::c_str() const
{
return _str;
}
}寫(xiě)一個(gè)測(cè)試函數(shù),也放在Rustle命名空間中,這樣就string前面不用加域名限制符。
namespace Rustle
{
void test_string1()
{
string s1("hello world");
cout << s1.c_str() << endl;
}
}運(yùn)行結(jié)果如下:

2.2 size,重載符號(hào)[ ],begin和end函數(shù)
- size是獲取字符個(gè)數(shù)的函數(shù),直接返回_size就好。
- [ ]下標(biāo)訪問(wèn)符,跟vector容器作用相似,訪問(wèn)pos下標(biāo)的元素,需要先斷言檢查pos是不是在合理的范圍,然后直接返回_str[pos]即可。不過(guò)返回類(lèi)型是字符類(lèi)型的引用,這樣可以對(duì)該字符進(jìn)行修改
- begin函數(shù)是返回字符串的第一個(gè)字符的地址,還有一個(gè)const修飾函數(shù),算是函數(shù)重載。因?yàn)閟tring類(lèi)對(duì)象可能也被const修飾。
- end函數(shù)返回的是字符串最后一字符的下一個(gè)位置,由于下標(biāo)是從0開(kāi)始的,直接返回_str+_size即可。
string::iterator string::begin()
{
return _str;
}
string::iterator string::end()
{
return _str + _size;
}
string::const_iterator string::begin() const
{
return _str;
}
string::const_iterator string::end() const
{
return _str+ _size;
}
size_t string::size() const
{
return _size;
}
char& string::operator[](size_t pos)
{
assert(pos < _size);
return _str[pos];
}
const char& string::operator[](size_t pos) const
{
assert(pos < _size);
return _str[pos];
}
}寫(xiě)一個(gè)測(cè)試函數(shù),用下標(biāo)訪問(wèn),迭代器訪問(wèn),還有范圍for循環(huán)訪問(wèn)。范圍for的底層就是需要識(shí)別有沒(méi)有begin和end函數(shù)。
void test_string1()
{
string s1("hello world");
cout << s1.c_str() << endl;
for (size_t i = 0; i < s1.size(); i++)
{
cout << s1[i] << " ";
}
cout << endl;
for (auto e : s1)
{
cout << e << " ";
}
cout << endl;
string::iterator it1 = s1.begin();
while (it1 != s1.end())
{
cout << *it1 << " ";
++it1;
}
cout << endl;
const string s3("xxxxxx");
string::const_iterator it2 = s3.begin();
while (it2 != s3.end())
{
cout << *it2 << " ";
++it2;
}
cout << endl;
}運(yùn)行結(jié)果如下:

2.3 push_back,reserve,append,+=運(yùn)算符重載
接口函數(shù)聲明如下,其中+=運(yùn)算符重載函數(shù)有兩個(gè)重載,針對(duì)的是字符和字符串的。
void reserve(size_t n); void push_back(char ch); void append(const char* str); string& operator+=(char ch); string& operator+=(const char* str);
- reserve就是調(diào)整容量的函數(shù)。我們需要手動(dòng)擴(kuò)容。先開(kāi)辟一個(gè)新容量大小的空間,然后使用strcpy庫(kù)函數(shù)將原字符串內(nèi)容拷貝到tmp指針指向的空間上,再釋放_(tái)str指向的空間。讓_str指針指向tmp指向的空間,修改_capacity的大小。
- push_back函數(shù)是在字符串的末尾加上一個(gè)字符。首先,我們要判斷字符串的容量是否足夠。當(dāng)_size和_capacity相等時(shí),說(shuō)明字符串容量已滿,需要擴(kuò)容。我們定義一個(gè)newcapacity變量,如果_capacity等于0,說(shuō)明還沒(méi)有開(kāi)空間,先給四個(gè)字符大小的容量大小,如果不等于0,按兩倍擴(kuò)容。擴(kuò)容之后,在_size下標(biāo)位置添加ch字符,并且需要單獨(dú)處理斜杠0,加在新字符的后一個(gè)位置。修改_size。
- append函數(shù)在原字符串上追加新字符串,會(huì)覆蓋原字符串。先定義len表示新字符串字符的個(gè)數(shù),再判斷加上新字符串后是否超過(guò)容量,超過(guò)容量要擴(kuò)容。然后使用strcpy拷貝新字符串,再修改_size。
- +=運(yùn)算符重載針對(duì)字符和字符串的兩個(gè)函數(shù),分別復(fù)用push_back和append函數(shù)即可。需要返回*this。
void string::reserve(size_t n)
{
if (n > _capacity)
{ //給斜杠0預(yù)留一個(gè)位置
char* tmp = new char[n + 1];
strcpy(tmp, _str);
delete[] _str;
_str = tmp;
_capacity = n;
}
}
void string::push_back(char ch)
{
if (_size == _capacity)
{
size_t newcapacity = _capacity == 0 ? 4 : _capacity * 2;
reserve(newcapacity);
}
_str[_size] = ch;
_str[_size + 1] = '\0';//單獨(dú)處理斜杠0
++_size;
}
void string::append(const char* str)
{
size_t len = strlen(str);
if (_size + len > _capacity)
{
reserve(_size + len);
}
strcpy(_str + _size, str);
_size += len;
}
//復(fù)用push_back和append函數(shù)
string& string::operator+=(char ch)
{
push_back(ch);
return *this;
}
string& string::operator+=(const char* str)
{
append(str);
return *this;
}寫(xiě)個(gè)測(cè)試函數(shù),測(cè)試剛剛是模擬實(shí)現(xiàn)的函數(shù)。
void test_string2()
{
string s1("hello world");
cout << s1.c_str() << endl;
s1.push_back('x');
cout << s1.c_str() << endl;
s1.append("aaaaaa");
cout << s1.c_str() << endl;
s1 += 'y';
cout << s1.c_str() << endl;
s1 += "dfsdf";
cout << s1.c_str() << endl;
}運(yùn)行結(jié)果如下:

2.4 insert和erase函數(shù)
- 上面是insert和erase函數(shù)的定義。insert函數(shù)從pos位置開(kāi)始插入字符或者字符串,erase函數(shù)從pos位置開(kāi)始,刪除len個(gè)字符,其中l(wèi)en變量給了缺省值npos。
- npos是無(wú)符號(hào)整數(shù),現(xiàn)在令npos = -1。如果
size_t是 32 位的,那么npos等于2^32 - 1,即4294967295。如果size_t是 64 位的,那么npos等于2^64 - 1,即18446744073709551615。總之是一個(gè)非常大的數(shù)字,表示直接到末尾。
class string
{
public:
void insert(size_t pos, char ch);
void insert(size_t pos, const char* str);
void erase(size_t pos, size_t len = npos);
private:
const static size_t npos;
}
- npos是一個(gè)靜態(tài)變量需要定義和聲明分離。
- 實(shí)現(xiàn)針對(duì)字符插入的insert函數(shù)。先判斷是否需要擴(kuò)容,然后需要挪動(dòng)元素,當(dāng)你定義一個(gè)無(wú)符號(hào)整型end變量時(shí),盡量不要讓無(wú)符號(hào)整數(shù)遇到大于等于或者小于等于符號(hào),會(huì)有坑。
- 因?yàn)槿绻鉾hile循環(huán)繼續(xù)的條件是end >= pos,并且此時(shí)pos等于0的情況下,你不斷讓end減1,當(dāng)end減到0時(shí),再次減去1會(huì)變成-1,如上面所說(shuō)相當(dāng)于
2^32 - 1,會(huì)造成無(wú)限循環(huán)。 - 有兩種解決方法,第一種就是不要出現(xiàn)等于符號(hào),控制好end的位置。第二種是強(qiáng)轉(zhuǎn)pos為int,這樣使用等于判斷就不會(huì)出現(xiàn)無(wú)限循環(huán)的情況。
- 針對(duì)字符串插入的insert函數(shù),使用上面第一種方法挪動(dòng)元素,while循環(huán)繼續(xù)的條件比較難寫(xiě)出來(lái),需要畫(huà)圖理解。
- 實(shí)現(xiàn)erase函數(shù),先判斷刪除的字符個(gè)數(shù)和從pos位置的字符到結(jié)尾字符個(gè)數(shù)的大小關(guān)系。如果大于原字符的個(gè)數(shù),直接將斜杠0放在pos位置的字符即可,在修改_size的大小。如果小于,需要挪動(dòng)元素,可以使用strcpy將刪除字符的最后一個(gè)位置拷貝到pos位置,就完成了刪除和挪動(dòng)的操作。
const size_t string::npos = -1;
//1.
void string::insert(size_t pos, char ch)
{
assert(pos <= _size);
if (_size == _capacity)
{
size_t newcapacity = _capacity == 0 ? 4 : _capacity * 2;
reserve(newcapacity);
}
//size_t無(wú)符號(hào)整數(shù)遇到大于等于有坑
size_t end = _size + 1;
while (end > pos)
{
_str[end] = _str[end - 1];
--end;
}
_str[pos] = ch;
++_size;
}
//2.
void string::insert(size_t pos, char ch)
{
assert(pos <= _size);
if (_size == _capacity)
{
size_t newcapacity = _capacity == 0 ? 4 : _capacity * 2;
reserve(newcapacity);
}
int end = _size;
while (end >= (int)pos)
{
_str[end + 1] = _str[end];
--end;
}
_str[pos] = ch;
++_size;
}
//1.
void string::insert(size_t pos, const char* str)
{
assert(pos <= _size);
size_t len = strlen(str);
if (_size + len > _capacity)
{
reserve(_size + len);
}
size_t end = _size + len;
while (end > pos + len - 1)//!(pos + len - 1)
{
_str[end] = _str[end - len];
--end;
}
memcpy(_str + pos, str, len);
_size += len;
}
//2.
void string::insert(size_t pos, const char* str)
{
assert(pos <= _size);
size_t len = strlen(str);
if (_size + len > _capacity)
{
reserve(_size + len);
}
int end = _size;
while (end >= (int)pos)
{
_str[end + len] = _str[end];
--end;
}
memcpy(_str + pos, str, len);
_size += len;
}
void string::erase(size_t pos, size_t len)
{
assert(pos < _size);
if (pos + len >= _size)
{
_str[pos] = '\0';
_size = pos;
}
else
{
strcpy(_str + pos, _str + pos + len);
_size -= len;
}
}寫(xiě)個(gè)測(cè)試函數(shù)。測(cè)試一下模擬實(shí)現(xiàn)的函數(shù)。
void test_string3()
{
string s1("hello world");
cout << s1.c_str() << endl;
s1.insert(0, 'x');
cout << s1.c_str() << endl;
string s2("helloworld");
s2.insert(5, "xxxx");
cout << s2.c_str() << endl;
s2.erase(5, 4);
cout << s2.c_str() << endl;
}運(yùn)行結(jié)果如下:

2.5 find和substr函數(shù)
函數(shù)原型如下,find函數(shù)是查找某個(gè)字符或者字符串的位置,查找到返回該字符的下標(biāo)位置或者該字符串第一個(gè)字符的位置。如果沒(méi)有找到返回-1,是一個(gè)極大的數(shù)。substr函數(shù)是從pos位置開(kāi)始,取下原字符串的子串,返回一個(gè)string類(lèi)的對(duì)象。
size_t find(char ch, size_t pos = 0); size_t find(const char* str, size_t pos = 0); string substr(size_t pos = 0, size_t len = npos);
- 查找字符,直接遍歷整個(gè)字符串查找,找到返回下標(biāo),沒(méi)找到返回-1。
- 查找字符串,可以直接使用strstr庫(kù)函數(shù),或者使用其他查找子串的算法。
- 實(shí)現(xiàn)substr函數(shù),先判斷子串字符個(gè)數(shù)是否小于從pos位置開(kāi)始的字符個(gè)數(shù)。如果大于,直接拷貝pos位置的字符串。如果小于,創(chuàng)建一個(gè)string類(lèi)的臨時(shí)對(duì)象,先調(diào)整容量為len個(gè),這樣就不會(huì)在頻繁擴(kuò)容。然后使用for循環(huán)一個(gè)個(gè)加等。
size_t string::find(char ch, size_t pos)
{
for (size_t i = 0; i < _size; i++)
{
if (_str[i] == ch)
return i;
}
return npos;
}
size_t string::find(const char* str, size_t pos)
{
const char* end = strstr(_str, str);
return end - _str;
}
string string::substr(size_t pos, size_t len)
{
//子串長(zhǎng)度大于從原字符串給定位置開(kāi)始到結(jié)束的長(zhǎng)度,直接拷貝返回
if (len > _size - pos)
{
string sub(_str + pos);
return sub;
}
else
{
string sub;
sub.reserve(len);
for (size_t i = 0; i < len; i++)
{
sub += _str[pos + i];
}
return sub;
}
}寫(xiě)一個(gè)測(cè)試用例,用于分割網(wǎng)址。
void test_string4()
{
string s1("helloworld");
cout << s1.find('o') << endl;
cout << s1.find("orl") << endl;
string url("https://legacy.cplusplus.com/reference");
size_t pos1 = url.find(":");
string url1 = url.substr(0, pos1);
cout << url1 << endl;
size_t pos2 = url.find('/', pos1 + 3);
string url2 = url.substr(pos1 + 3, pos2 - (pos1 + 3));
cout << url2 << endl;
string url3 = url.substr(pos2 + 1);
cout << url3 << endl;
}運(yùn)行結(jié)果如下:

2.6 比較運(yùn)算符的重載
bool operator<(const string& s)const;
bool operator>(const string& s)const;
bool operator<=(const string& s)const;
bool operator>=(const string& s)const;
bool operator==(const string& s)const;
bool operator!=(const string& s)const;比較運(yùn)算符,是比較字符的ASCii碼值,可以寫(xiě)完<和==的邏輯,然后其他進(jìn)行復(fù)用。
bool string::operator<(const string& s)const
{
return strcmp(_str, s._str) < 0;
}
bool string::operator>(const string& s)const
{
return !(*this < s) && !(*this == s);
}
bool string::operator<=(const string& s)const
{
return *this < s || *this == s;
}
bool string::operator>=(const string& s)const
{
return *this < s || *this == s;
}
bool string::operator==(const string& s)const
{
return strcmp(_str, s._str) == 0;
}
bool string::operator!=(const string& s)const
{
return !(*this == s);
}2.7 cout<<和cin>>運(yùn)算符重載
重載流插入<<和流提取>>這兩個(gè)操作符,是為了方便打印和輸入。并且這是放在全局的函數(shù)。
istream& operator>>(istream& is, string& str); ostream& operator<<(ostream& os, const string& str);
- 流插入<<函數(shù)容易實(shí)現(xiàn),直接for循環(huán)遍歷打印每個(gè)字符即可,不過(guò)你可以按照你的意愿打印任何形式。
- 流提取<<函數(shù)比較難實(shí)現(xiàn)。首先寫(xiě)一個(gè)clear函數(shù),清理掉之前的字符串里的字符,可以直接將斜杠0放在下標(biāo)為0的位置,再修改_size就好了。
- 首先,我們不能直接使用is >> ch來(lái)提取字符,因?yàn)橐挥龅娇崭窕蛘邠Q行就表示分割。可以使用is.get()函數(shù)完成輸入操作。然后,我們先創(chuàng)建一個(gè)字符數(shù)組,輸入的字符填到字符數(shù)組先,滿了在加載字符串中,可以防止頻繁擴(kuò)容,帶來(lái)的消耗。
ostream& operator<<(ostream& os, const string& str)
{
for (size_t i = 0; i < str.size(); i++)
{
os << str[i];
}
return os;
}
void string::clear()
{
_str[0] = '\0';
_size = 0;
}
istream& operator>>(istream& is, string& str)
{
//空格和換行表示多個(gè)值的分割
//is >> ch; //scanf("%c", &ch);
str.clear();
int i = 0;
char buff[128];
char ch = is.get();
while (ch != ' ' && ch != '\n')
{
buff[i++] = ch;
//0~126的位置放字符了,留一個(gè)位置給斜杠0
//減少頻繁擴(kuò)容
if (i == 127)
{
buff[i] = '\0';
str += buff;
i = 0;
}
ch = is.get();
}
if (i != 0)
{
buff[i] = '\0';
str += buff;
}
return is;
}寫(xiě)個(gè)測(cè)試函數(shù)。
void test_string7()
{
//string s1("hello world");
string s1;
cout << s1 << endl;
cin >> s1;
cout << s1 << endl;
}運(yùn)行結(jié)果如下:

總結(jié)
以上就是C++ string字符串的使用和簡(jiǎn)單模擬實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于C++ string使用和實(shí)現(xiàn)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- VS C++頭文件引用提示“未定義標(biāo)識(shí)符”的問(wèn)題解決
- C++標(biāo)準(zhǔn)庫(kù)介紹及使用string類(lèi)的詳細(xì)過(guò)程
- C++模擬實(shí)現(xiàn)string的詳細(xì)過(guò)程
- C++ string類(lèi)getline()用法實(shí)例詳解
- C/C++實(shí)現(xiàn)string和int相互轉(zhuǎn)換的常用方法總結(jié)
- 如何解決C++未定義標(biāo)識(shí)符 “string“、未定義標(biāo)識(shí)符 “cout“、“name”:未知重寫(xiě)說(shuō)明符錯(cuò)誤
相關(guān)文章
數(shù)據(jù)結(jié)構(gòu) C語(yǔ)言實(shí)現(xiàn)循環(huán)單鏈表的實(shí)例
這篇文章主要介紹了數(shù)據(jù)結(jié)構(gòu) C語(yǔ)言實(shí)現(xiàn)循環(huán)單鏈表的實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-05-05
c++基礎(chǔ)語(yǔ)法:構(gòu)造函數(shù)與析構(gòu)函數(shù)
構(gòu)造函數(shù)用來(lái)構(gòu)造一個(gè)對(duì)象,主要完成一些初始化工作,如果類(lèi)中不提供構(gòu)造函數(shù),編譯器會(huì)默認(rèn)的提供一個(gè)默認(rèn)構(gòu)造函數(shù)(參數(shù)為空的構(gòu)造函數(shù)就是默認(rèn)構(gòu)造函數(shù)) ;析構(gòu)函數(shù)是隱式調(diào)用的,delete對(duì)象時(shí)候會(huì)自動(dòng)調(diào)用完成對(duì)象的清理工作2013-09-09
C語(yǔ)言中const和define的區(qū)別你了解嘛
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言中const和define的區(qū)別,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-03-03
C語(yǔ)言實(shí)現(xiàn)電影管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)電影管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08
解決Visual?Studio?Code錯(cuò)誤Cannot?build?and?debug?because?
這篇文章主要為大家介紹了解決Visual?Studio?Code錯(cuò)誤Cannot?build?and?debug?because?the及分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-07-07
VS2022永久配置OpenCV開(kāi)發(fā)環(huán)境的實(shí)現(xiàn)
本文主要介紹了VS2022永久配置OpenCV開(kāi)發(fā)環(huán)境的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
解析C++中的for循環(huán)以及基于范圍的for語(yǔ)句使用
這篇文章主要介紹了解析C++中的for循環(huán)以及基于范圍的for語(yǔ)句使用,是C++入門(mén)學(xué)習(xí)中的基礎(chǔ)知識(shí),需要的朋友可以參考下2016-01-01
C語(yǔ)言實(shí)現(xiàn)循環(huán)雙鏈表
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)循環(huán)雙鏈表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11

