1. 程式人生 > >main函式為什麼有引數,std::是什麼,STL是什麼

main函式為什麼有引數,std::是什麼,STL是什麼

1 main函式為什麼有引數 分別代表什麼意思  

#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
    for(int i=0;i<argc;i++)
        cout<<argv[i]<<endl;
    return 0;
}

其中,argc = argument count :表示傳入main函式的陣列元素個數為int型別

而 argv = argument vector :表示傳入main函式的指標陣列,為char**型別

第一個陣列元素argv[0]是程式名稱並且包含程式所在的完整路徑,argc至少為1,即argv陣列至少包含程式名

2 std::是什麼意思 起什麼作用

#include <string>
#include <iostream>
#include <string.h>

int main(int argc,chqr const*argv[]){
    std::string str("hello");
    str.append(1,'\0');
    str.append(1,'i');

    std::cout<<str.size()<<std::endl;
    std::cout<<str<<std::endl;
    std::cout<<std.compare("hello")<<std::endl;
    std::cout<<strcmp(str.c_str(),"hello")<<std::endl;

    return 0;
}

std是一個類(輸入輸出標準),它包括了cin成員和cout成員,using name space std ;以後才能使用它的成員。

#include<iostream.h>中不存在類std,但是他又cin,out的相關函式,不需要使用名稱空間了。

而第二種標準#include<iostream>,它包含了一個類,在類的使用之前要預處理一下,using namespace std;然後就可以使用

cin,cout這兩個成員函數了,假設你不使用預處理(using namespace std;),麻煩加上std::cin或者std::cout再去使用它的成員函式

(標頭檔案中存在這個類)

3 STL = Standard Template Library

STL = Standard Template Library,標準模板庫。

從根本上說,STL是一些“容器”的集合,這些“容器”有list,vector,set,map等,STL也是演算法和其他一些元件的集合。

STL現在是C++的一部分,因此不用額外安裝什麼。它被內建在你的編譯器之內。

在C++標準中,STL被組織為下面的13個頭檔案:<algorithm>、<deque>、<functional>、<iterator>、<vector>、<list>、<map>、<memory>、<numeric>、<queue>、<set>、<stack>和<utility>