日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

没事聊聊C++局域网聊天软件

發(fā)布時(shí)間:2025/3/15 c/c++ 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 没事聊聊C++局域网聊天软件 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

通常情況,我們?cè)诰钟蚓W(wǎng)聊天的時(shí)候基本上是按照都是按照對(duì)象的屬性都合并在一個(gè)模型中,其實(shí)當(dāng)在設(shè)計(jì)這個(gè)對(duì)象的模型的時(shí)候,我們有沒(méi)有考慮過(guò)模型粒度細(xì)化呢,雖然模型粒度細(xì)化會(huì)提高維度的成本,但是也提高的系統(tǒng)的靈活性,首要條件就是模型的粒度細(xì)化要合理化。(本文只講設(shè)計(jì)不講模型屬性字段的屬性問(wèn)題)局域網(wǎng)聊天軟件下載:http://www.freeeim.com/

c.max_size()
Returns the maximum number of elements possible

c1.swap(c2)/swap(c1, c2)
Swaps the data of c1and c2

c.begin() / c.end()
Returns an iterator for the first element/ the position after the last element

c.rbegin()
Returns a reverse iterator for the first element of a reverse iteration

c.rend()
Returns a reverse iterator for the position after the last element of a reverse iteration

c.insert(pos,elem)
Inserts a copy of elem (return value and the meaning of pos differ)

c.erase(beg,end)
Removes all elements of the range [beg,end) (some containers return next element not removed)

c.clar()
Removes all elements (makes the container empty)

2.(P149)
vector的大小(size)和容量(capacity)

size指示當(dāng)前容器的元素?cái)?shù)量

capacity指示vector可以容納的元素?cái)?shù)量,超過(guò)這個(gè)值就會(huì)重新配置內(nèi)部存儲(chǔ)器。

使用resize(num)或resize(num, elem)將元素?cái)?shù)量改為num個(gè)。

使用reserve(num)將vector可容納數(shù)量改為num

capacity >= size

vector容器不能向不存在的空間賦值,也就是說(shuō),vector的assign()可以賦值的范圍是[begin(), end)。注意這是size的范圍,不是capacity的范圍。

3.(P158)
Class vector<bool>

貌似這個(gè)不怎么用,確切的說(shuō)是不好。

《Effective C++》里面就說(shuō)道了:避免使用vector<bool>

而且在網(wǎng)上也找了一篇討論帖:

http://topic.csdn.net/t/20040511/15/3054586.html

4.(P163)
Deque

deque與vector大部分類似,以下是幾個(gè)不同點(diǎn):

1.deque不提供容量操作( capacity()和reserve() )。

2.deque直接提供頭部元素的插入和刪除(push_front() 和 pop_front() )

deque還有個(gè)特點(diǎn),元素的插入或刪除可能導(dǎo)致內(nèi)存重新分配,所以任何插入或者刪除動(dòng)作都會(huì)使所有指向deque元素的pointer, reference, iterator失效。唯一的例外是在頭部或尾部插入元素。

5.(P169)
List

list增加了remove()和remove_if()的特殊版本作為自己的成員函數(shù)。因此,面對(duì)list,應(yīng)該調(diào)用成員函數(shù)remove()而不是面向vector<>或deque<>那樣調(diào)用的STL算法。

List的特殊變動(dòng)性操作(Special Modifying Operations)

?

關(guān)于Splice函數(shù),注意通過(guò)鏈表來(lái)理解如何轉(zhuǎn)移,比如:

c1.splice(pos, c2)操作后,原c2內(nèi)就為空了。

看下面這個(gè)例子,注意結(jié)果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Author: Tanky Woo
// Blog: www.wutianqi.com
#include <cstddef>
#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <algorithm>
#include <iterator>
using namespace std;

void printLists (const list<int>& l1, const list<int>& l2)
{
cout << "list1: ";
copy (l1.begin(), l1.end(), ostream_iterator<int>(cout," "));
cout << endl << "list2: ";
copy (l2.begin(), l2.end(), ostream_iterator<int>(cout," "));
cout << endl << endl;
}

int main()
{
// create two empty lists
list<int> list1, list2;

// fill both lists with elements
for (int i=0; i<6; ++i) {
list1.push_back(i);
list2.push_front(i);
}
printLists(list1, list2);

// insert all elements of list1 before the first element with value 3 of list2
// – find() returns an iterator to the first element with value 3
list2.splice(find(list2.begin(),list2.end(), // destination position
3),
list1); // source list
printLists(list1, list2);

// move first element to the end
list2.splice(list2.end(), // destination position
list2, // source list
list2.begin()); // source position
printLists(list1, list2);

// sort second list, assign to list1 and remove duplicates
list2.sort();
list1 = list2;
list2.unique();
printLists(list1, list2);

// merge both sorted lists into the first list
list1.merge(list2);
printLists(list1, list2);
system("PAUSE");
return EXIT_SUCCESS;

}

結(jié)果為:

list1: 0 1 2 3 4 5
list2: 5 4 3 2 1 0

list1:
list2: 5 4 0 1 2 3 4 5 3 2 1 0

list1:
list2: 4 0 1 2 3 4 5 3 2 1 0 5

list1: 0 0 1 1 2 2 3 3 4 4 5 5
list2: 0 1 2 3 4 5

list1: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5
list2:

6.(P180)
set/multiset的特殊搜尋函數(shù)

就像list提供了特殊版本的remove(),remove_if()一樣,set/multiset也提供了特殊的搜尋函數(shù),他們比同名的STL函數(shù)能夠更快的執(zhí)行相應(yīng)工作。

count (elem)
Returns the number of elements with value elem

find(elem)
Returns the position of the first element with value elem or end()

lower_bound(elem)
Returns the first position, where elem would get inserted (the first element >= elem)

upper_bound (elem)
Returns the last position, where elem would get inserted (the first element > elem)

equal_range (elem)
Returns the first and last position, where elem would get inserted (the range of elements == elem)


7.(P181)
對(duì)于set/multiset的賦值(assign)或交換(swap),如果準(zhǔn)則不同,準(zhǔn)則本身也會(huì)被賦值或者交換

8.(P183)
set/multiset未提供remove()操作。但是卻可以直接c.erase(elem)刪除”與elem相等”的元素。

set/multiset的安插(insert)型函數(shù)一次只能插入一個(gè)元素。

set的安插(insert)函數(shù)返回值是個(gè)pair型,first表示新元素的位置或者已含有的相同元素的位置;second表示是否安插成功。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
std::pair<std::set<float>::iterator,bool> status;

//insert value and assign return value
status = c.insert(value);

//process return value
if (status.second) {
std::cout << value << " inserted as element "
}
else {
std::cout << value << " already exists as element "
}
std::cout << std::distance(c.begin().status.first) + 1
<< std::endl;

9.(198)
可以把set/multiset視為特殊的map/multimap,只不過(guò)set元素的value和key指向同一對(duì)象。因此map/multimap擁有set/multiset的所有能力和所有操作函數(shù)。

map/multimap和set/multimap一樣,自身提供了特殊的搜尋函數(shù)。注意這里的成員函數(shù)find()的參數(shù)是key,也就是說(shuō),不能以find()搜尋擁有某特定value的元素,不過(guò)可以用find_if()。count(key),find(key), lower_bound(key),upper_bound(key), equal_range(key)等參數(shù)都是key。

在 map/multimap中,所有元素的key都被視為常數(shù)。因此元素的實(shí)質(zhì)類型是pair<const key, T>。這個(gè)限制是為了確保你不會(huì)因?yàn)樽兏氐膋ey而破壞已排序好的元素次序。

map的下標(biāo)操作要熟悉,并且下標(biāo)操作得到的直接是value。

本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/mynote/archive/2011/01/27/6167199.aspx

總結(jié)

以上是生活随笔為你收集整理的没事聊聊C++局域网聊天软件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。