Cpp學習雜記

2021-10-03 10:20:26 字數 1615 閱讀 2952

#include

using

namespace std;

typedef

struct time *shijian;

struct time

;int

main()

; shijian t2

; cout <<

"input year:"

>t1.year;

cout<<

"input month:"

>t1.month;

cout<<

"input date:"

>t1.date;

cout<<

"the time is: "

<" - "

<" - "

}

typedef struct time *shijian 這句話,斷句如下:

typedef / struct time * / shijian

把struct time * 可用shijian整體替換。

main中的第一行struct time t1,中t1是struct time型別;第二行的shijian t2中t2是struct time型的指標。

//explicit 一般用來修飾類的建構函式,如果在某些情況下,我們要求類的使用者必須顯式呼叫類的建構函式時就需要使用explicit,反之預設型別轉換可能會造成無法預期的問題.

//例如:string類

class

string

;string::

string

(int n)

string::

string

(const

char

* s)

intmain

(int argc,

char

* ar**)

c++中只有 非靜態成員變數 才屬於類的物件,例如:
#include

using

namespace std;

class

clock

void

showtime()

private

:int hour, minute, second;};

intmain()

這裡面的結果是t的sizeof為12byte,因為clock物件中有3個int型非靜態成員變數。每個int型變數佔4byte。

全域性變數定義一次,在多個原始檔中都可使用,其他原始檔中使用時需要用「extern」關鍵字宣告一下,告訴編譯器在某個原始檔中有乙個全域性變數。

靜態變數在記憶體儲存方式上與全域性變數沒有區別,靜態全域性變數只對本原始檔有效,對其他原始檔無效。具體用法區別如下。

#include

<...........>

int global=1;

//宣告外部鏈結的變數

static

int global2 //宣告內部鏈結的變數

intfunc()

intmain()

python 學習雜記

一 模組匯入問題 如果在機器上安裝了多個版本的python,往往會有匯入錯誤,例如一般的python程式頭都寫的是 usr bin env python 這個實際是 usr bin python 但是如果新版本的python是後安裝的,且沒有 prifex usr 可能這個鏈結仍指向老版本pytho...

Python學習雜記

學習資料 python核心程式設計 第二版 class c object foo 100 name 是給定類的字元名字,它適用於那種只需要字串 類物件的名字 而非類物件本身的情況。內建的型別也有這個屬性。type 123 str type 123 name str type type 123 typ...

學習筆記雜記

命令 具體操作 ls顯示檔案或目錄 l列出檔案詳細資訊l list a列出當前目錄下所有檔案及目錄,包括隱藏的a all mkdir 建立目錄 p建立目錄,若無父目錄,則建立p parent cd切換目錄 touch 建立空檔案 echo 建立帶有內容的檔案。cat檢視檔案內容 cp拷貝 mv動或重...