coding邊學邊記之C

2021-09-03 06:58:11 字數 4372 閱讀 6814

1.c++中定義函式要有析構函式

2.c++中自定義標頭檔案需要

#ifndef code_cpp_global_h

#define code_cpp_global_h

#endif

//code_cpp_global_h

3.c++中的map插入鍵值對時,一定要先檢查鍵是否存在,因為:

-a.如果插入相同鍵的操作,無論是編譯和執行時都不會報錯

-b.對於插入的資料的鍵值已存在,那麼這個插入操作將會被忽略

菜鳥教程:c++類的建構函式和析構函式

(1)過載運算子和過載函式

(2)輸入/輸出運算子過載

double qty;

int i_qty =

(int

)(qty +

0.5)

;

(1)

(2)使用迭代器(反向迭代器)可進行順序(逆序)排序,預設是從小到大:

順序:

#include

#include

#include

using namespace std;

intmain()

結果:空格dehllloorw

逆序:

#include

#include

#include

using namespace std;

intmain()

結果:wroolllhde空格

auto可以在宣告變數的時候根據變數初始值的型別自動為此變數選擇匹配的型別,用於代替冗長複雜、變數使用範圍專一的變數宣告。

對於乙個map,以下兩行的迴圈是錯誤的,map不能用i如下遍歷:

for(int i=

0; isize()

; i++)

taskinfo* pinfo = map[i]

;

一種正確的遍歷:

map<

char

,string>

mp;map<

char

,string>

::iterator it;

intmain

(int argc,

char

const

*argv)

(1)

benchmark.txt內容如下:

620000044158676000	1	a10	33.200520833333336

620000044135169000 9 a11 49.76450704225352

620000044128782000 1 a02 35.15409035409036

620000044128968000 1 a02 59.412454212454215

620000044129080000 1 a02 56.10329670329671

620000044130416000 1 a14 71.11111111111111

620000044126894000 2 a09 42.328711528429835

620000044126899000 2 a03 66.66666666666667

620000044136505000 1 a08 42.30769230769231

620000044136571000 1 a08 46.36923076923077

620000044137207000 1 a12 16.768559272300468

620000044131144000 2 a03 60.827481481481485

620000044132226000 2 a13 78.73167701863353

620000044139178000 4 a08 53.53641025641026

620000044162027000 1 a02 68.33191697191697

620000044106464000 3 a09 71.75880020865937

c++**:

#include 

#include

#include

#include

#include

using namespace std;

class

problem;~

problem()

;public

: std:

:string oid;

int qty;

std:

:map<

int,

int>

num;

std:

:string benchmark_sol_carton;

double benchmark_sol_utl;};

intmain()

fin.

close()

;// set value for map_order

fin.

open

(filename.

c_str()

);if(fin.

fail()

) std:

:string or_id;

while

(fin >> or_id)

fin.

close()

;// check the value of map_order

for(it = map_order.

begin()

; it != map_order.

end();

++it)

cout << it-

>first <<

" = "

<< it-

>second.qty << endl;

return0;

}

執行結果:

620000044158676000	1	a10	33.200520833333336

620000044135169000 9 a11 49.76450704225352

620000044128782000 1 a02 35.15409035409036

620000044128968000 1 a02 59.412454212454215

620000044129080000 1 a02 56.10329670329671

620000044130416000 1 a14 71.11111111111111

620000044126894000 2 a09 42.328711528429835

620000044126899000 2 a03 66.66666666666667

620000044136505000 1 a08 42.30769230769231

620000044136571000 1 a08 46.36923076923077

620000044137207000 1 a12 16.768559272300468

620000044131144000 2 a03 60.827481481481485

620000044132226000 2 a13 78.73167701863353

620000044139178000 4 a08 53.53641025641026

620000044162027000 1 a02 68.33191697191697

620000044106464000 3 a09 71.75880020865937

620000044106464000 = 3

620000044126894000 = 2

620000044126899000 = 2

620000044128782000 = 1

620000044128968000 = 1

620000044129080000 = 1

620000044130416000 = 1

620000044131144000 = 2

620000044132226000 = 2

620000044135169000 = 9

620000044136505000 = 1

620000044136571000 = 1

620000044137207000 = 1

620000044139178000 = 4

620000044158676000 = 1

620000044162027000 = 1

process finished with exit code 0

awk邊學邊記

awk中的rs ors fs ofs的簡要說明 縮寫我認為的全拼 含義預設值 rsrow separator awk讀取檔案時的行分隔符 預設為 n orsoutput row separator awk輸出時的行分隔符 預設為 n fsfield separator awk讀取檔案時的列 字段 域...

FFMPEG邊學邊記

沒有參考資料,看ffmpeg真的是一種折磨 尤其是像我這種英語不好的 說白了邊學邊記,就把參考的直接放前面 1.雷大神的ffmpeg獲取directshow裝置資料 攝像頭,錄屏 2.基於ffmpeg的c 錄屏全攻略 兩篇類似,不知道誰模仿誰的 windows平台下,使用 dshow取代x11gra...

MySql邊學邊記 1

mysql資料型別 mysql支援多種型別,大致可以分為三類 數值 日期 時間和字串 字元 型別。標準sql 資料型別 包括 嚴格數值資料型別 integer smallint decimal和numeric 以及近似數值資料型別 float real和double precision 同時也支援s...