随笔分类 - C/C++
摘要:系统 ubuntu10.041. 安装 :1 sudo apt-get install git-core 2. 初始化一个仓库repository1 mkdir mygit2 git init --bare mygit3. 初始化后,什么都木有,我们要建立一个master branch1 mkdir myprj2 cd myprj3 git init4 git add remote add origin ~/mygit5 git add *6 git commit -m "initail myprj"7 git push origin master 4. 好了,下面可以在其
阅读全文
摘要:对于数组A,一旦给定其维数n及各维长度bi(1≤i≤n),则该数组中元素的个数是固定的,不能对数组做插入和删除操作,不涉及移动数据元素操作,因此对于数组而言,采用顺序存储方式比较合适。我们知道,计算机内存器的结构是一维的,因此对于一维数组按下标顺序分配即可,而对多维数组,就必须按照某种次序,将数据元素排成一个线性序列,然后将这个线性序列存放在存储器中。数组的顺序存储结构有两种:一是以行为主序(或先行后列)的顺序存放,如BASIC、PASCAL、COBOL、C等程序设计语言中用的是以行为主的顺序分配,即一行分配完了接着分配下一行。另一种是以列为主序(先列后行)的顺序存放,如FORTRAN语言中.
阅读全文
摘要:Bind: Address Already in UseOr How to Avoid this Error when Closing TCP ConnectionsNormal ClosureIn order for a network connection to close, both ends have to sendFIN(final) packets, which indicate they will not send any additional data, and both ends mustACK(acknowledge) each other'sFINpackets.
阅读全文
摘要:Simple guide for Automake/AutoconfAbstractAutomake and Autoconf are great projects and tools in GNU. This paper can’t describe all but main steps. It will explian Automake and Autoconf in short but clear sentences.IntroduceEveryone who use Linux and Unix to program, knows that what is Makefile. Howe
阅读全文
摘要:首先是安装Eclipse,方法有两种:第一种是通过Ubuntu自带的程序安装功能安装Eclipse,应用程序->Ubtuntu软件中心,搜Eclipse安装即可。第二种方法是用命令:应用程序->附件->终端然后输入(中间可能需要你输入密码):sudo apt-get install eclipsesudo apt-get install eclipse-pdesudo apt-get install eclipse-jdt 解释:这个命令是在解决安装CDT(也就是能编译C/C++代码的插件)问题时搜到的一个博文里面的,其原文地址为:ubuntu上使用eclipse进行C/C+
阅读全文
摘要:Linux下IP转换工具::#Include #include #include strcut sockaddr_in src;src.sin_addr.s_addr = inet_addr("*.*.*.*"); //构建网络地址。printf("%s\n",inet_ntoa(src.sin_addr)); //将网络地址转换成字符串。注意::inet_ntoa存在的问题是inet_ntoa的返回值是一个static类型的char *指针,所以会出现问题::char *a1,a2;src.sin_addr.s_addr = inet_addr(&qu
阅读全文
摘要:NOTE: I’ve noticed a lot of traffic to this page for “local edit incoming delete on update” errors, which are not what this article is about (the solution below may or may not work for that — I have no idea). This article is about “localdelete, incoming delete on update” errors. Always back up your
阅读全文
摘要:Table of Contents Abstract A Minimal Project Editing Automake-based Projects with KDevelop Adding Doxygen Support A More Complex Example Topics Not Covered LinksAbstractThis article presents several simple Automake/Autoconf-based projects. I assume that you know what Automake, Autoconf, and configur
阅读全文
摘要:Implementing a Queue - Source Codeby Eric SuhThis source file is an implementation of the Queue class. The classis implemented with templates, and the size is determineddynamically at initialization (although the default is 500elements).For the templated class, the elements must have the operatorsd.
阅读全文
摘要:Stack Source Code in C++Special thanks to Eric Suh for contributing the followingimplementation of a stack. This implementation uses templates tofaciliate generic programming./ * ------------------------------------------------------------------- | | | Stack Class ...
阅读全文
摘要:對於使用new動態配置的資源,在不使用時必須記得delete,以釋放記憶體空間,然而動態記憶體配置很容易發生忘了delete,或是對同一個記憶體位址delete兩次(例如一個物件被指定給兩個指標),或是對一個已經被delete的位址再作讀寫動作。C++標準函式庫中提供auto_prt,可以協助您動態管理new而建立的物件,要使用auto_prt,您要含入memory表頭檔,例如:#includeauto_ptr可以指向一個以new建立的物件,當auto_ptr的生命週期結束後,所指向的物件之資源也會被釋放,在建立auto_ptr時必須指定目標物件之型態,例如:auto_ptriPtr (new
阅读全文
摘要:參考(Reference)型態代表了變數或物件的一個別名(Alias),參考型態可以直接取得變數或物件的位址,並間接透過參考型態別名來操作物件,作用類似於指標,但卻不必使用指標語法,也就是不必使用*運算子來提取值。要定義參考型態,在定義型態時於型態關鍵字後加上&運算子,例如:intvar = 10; // 定義變數int*ptr = &var; // 定義指標,指向var的位址int&ref = var; //定義參考,代表var變數上面的程式中,最後一行即是在定義參考型態,注意參考型態一定要初始化,例如下面的定義是不能通過編譯的:int&ref; // err
阅读全文
摘要:http://caterpillar.onlyfun.net/Gossip/CppGossip/CommandArg.html程式在執行時,可以附加一些引數以指定執行不同的功能,例如:copy-r ./temp ./tmp其中copy是程式名稱,而-r、./temp、./tmp都是在程式執行時附加給程式的一些引數,這種程式執行方式在以文字畫面為主的程式中相當常見,稱之為「命令列引數」(Command-lineargument)。在之前的程式中,您的main()函式在括號中總是空白的,而如要使用命令列引數,可以在括號中如下填寫:intmain(int argc, char *argv[]) {.
阅读全文
摘要:http://caterpillar.onlyfun.net/Gossip/CppGossip/newDelete.html到目前為止,您都是事先宣告好所要使用的變數,當程式開始執行時,這些變數就會自動被配置記憶體空間。然而有時有些變數並不知道何時會被使用,您希望在使用到的時候再配置空間給變數,並在變數不使用的時候,將變數所佔有的空間還給記憶體,這時候我們可以使用new運算子與delete運算子。舉個簡單的例子來說,您可以在程式中以動態的方式來配置一個int型態大小的記憶體,例如:int*ptr = new int;在這段程式中,new運算子會配置一個int所需要的空間,並傳回該空間的位址,所
阅读全文
摘要:直接操作字元陣列來進行字串操作是比較低階的行為,就如之前所說的,陣列本身對自己的長度沒有意識,所以無法判斷自己是否為空字串,而陣列也不能直接指定給另一個陣列,所以您無法直接將字串指定給另一個字串,您也無法對兩個字串直接進行串連的動作,例如:charstr1[] = "text1";charstr2[] = "text2";str1= str2; // errorcout您可以使用三種方式來建立一個string類別的物件(object),例如:stringstr1; // 建立一個string物件,內容為空字串stringstr2("caterp
阅读全文
摘要:http://caterpillar.onlyfun.net/Gossip/CppGossip/vector2.htmlvector的STL型式,其實就是以物件導向的方式來操作vector(如果您還沒接觸過物件導向程式設計,這邊介紹的可能稍有難度),以物件的方式來操作vector是比較被鼓勵的方式,以下將介紹幾個vector的基本操作。您可以建構一個元素為空的vector物件:vectorivector;如果打算將元素放入vector中,可以使用push_back(),例如:for(inti = 0; i ::iteratorit = ivector.begin();it!= ivector.
阅读全文
摘要:http://caterpillar.onlyfun.net/Gossip/CppGossip/vector1.html您可以使用vector來替代陣列,並使用陣列型式(Array idiom)的方式來操作vector,要使用vector,必須含入vector表頭檔:#include要建立vector型態的物件(Object),您必須提供元素型態與長度資訊,例如下例中建立int元素的vector,並擁有10個元素:vectorivector(10);您可以模彷陣列中存取元素的方式來存取vector的元素,使用下標(Subscript)運算子並指定索引來取得指定的元素,例如:#include .
阅读全文
摘要:http://www.ibm.com/developerworks/cn/linux/l-bppc/简介本文是为了满足开发人员的需要而写的。我们总结了一套指南,无论作为开发人员还是顾问,这些指南多年来一直都很好地指导着我们,我们把它们作为建议提供给您,希望对您的工作有所帮助。您也许不赞同其中的某些指南,但我们希望您会喜欢其中的一些并在您的编程或移植项目中使用它们。 回页首风格与指南 使用一种使代码具有可读性和一致性的源代码风格。如果没有团队代码风格或自己的风格,您可以使用与大多数 C 程序员采用的 Kernighan 和 Ritchie 风格相似的风格。然而,举一个极端的例子,有可能最终会写出
阅读全文
摘要:This article comes from there :http://www.cplusplus.com/reference/stl/vector/VectorVectorsare a kind of sequence container. As such, their elements areordered following a strict linear sequence.Vector containers are implemented as dynamic arrays; Just asregular arrays, vector containers have their e
阅读全文
摘要:Compiling your source code files can be tedious, specially when you want to include several source files and have to type the compiling command everytime you want to do it.Well, I have news for you... Your days of command line compilingare (mostly) over, because YOU will learn how to writeMakefiles.
阅读全文