標準庫中的名字(std cout)

2021-09-10 12:55:31 字數 391 閱讀 6812

#includeint main()

{ std::cout<<"enter two numbers:"<>v1>>v2;

std::cout<<"the sum of"《這段**使用了std::cout和std::endl 而不是直接用cout和endl,字首std::指出名字cout和endl是定義在std的命名空間(namespace)中的。命字空間可以幫助我們避免不經意的名字定義衝突,以及使用庫中相同名字導致衝突。標準庫定義的所有名字都在名字空間std中。

通過命名使用標準庫有乙個***:當使用標準庫中的乙個名字時,必須顯示說明我們想使用來命名空間std中的名字。eg:需要寫出std::cout,通過使用作用域運算子(::)來指出我們想使用定義在命名空間std中的名字cout。

未完待續~~

C 標準庫名字和標頭檔案

標準庫名字和標頭檔案 name 名字 header 標頭檔案name 名字 header 標頭檔案abort ios base accumulate isalpha allocator islower auto ptr ispunct back inserter isspace bad alloc ...

C 中的標準庫與非標準庫的區別

c 中我們要用到標準輸出,就需要呼叫cout,那麼,cout這條語句怎麼使用呢?例如 include 標頭檔案 int main std cout hello world include int main cout hello world 從這兩個函式來看都沒多大的區別,最後都是輸出 hello w...

使用標準庫中的模組

標準庫 系統自帶的 格式 import module1 module2,module3 modulen import優點 1 不管用import在同乙個檔案下執行多少次,系統預設只會真正匯入一次 2 防止同乙個模組一遍一遍執行 使用標準庫中模組中的內容 模組名.函式名 變數名 每次只引入乙個模組 i...