抽象編程學習筆記

來源:互聯網
上載者:User
文章目錄
  • class 1
  • class 2
  • class 3
class 1

    介紹了一些學習編程的事情,雖然沒有具體的講某種語言,但是還是很有用,能達到一些共鳴

    C++的安全性比Java略差,是因為創造C++的人希望程式員是自由的,因為很多時候如果要確保每個地方都沒有錯誤,會同時增加處理問題的時間。

    C++本身並不具備圖形系統,這就意味著windows mac 都有自己不同的圖形庫,這和java不同

class 2

     介紹C++和java文法上的區別,不會java,所以沒有細看

class 3

    

    string s="hello";    for(int i=0;i<s.length();i++)s[i]=toupper(s[i]);    cout<<s<<endl;    return 0;

這是一段很常見的string的使用,可是要注意到是用字串面值給string賦值的

來看一下string類的建構函式

inline String::String(const char* str){    if (!str) m_data=0;    else    {        m_data = new char[strlen(str)+1];        strcpy(m_data,str);    }}

應該調用的是這個建構函式,注意到裡面使用的是strcpy函數

char *strcpy(char *strDestination,const char *strSource)  {  assert(strDestination!=NULL && strSource!=NULL);  char *strD=strDestination;  while ((*strD++=*strSource++)!='\0');  return strDestination;  }

它其實是一個複製的過程,這就將不可以改變的字串面值轉化為了可以改變的string

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.