Time of Update: 2018-12-06
變數在範圍裡面被聲明的是什麼類型,就當作什麼類型來用。(1)參數是二維數組,但是要指定第二維的維數。int array[10][10];函式宣告:void fuc(int a[][10]);函數調用:fuc(array);——在函數fuc中,a是二維數組。使用a[i][j]形式來訪問數組中元素。(2)參數使用一維指標數組。int *array[10];for(i = 0; i < 10; i++) array[i] = new int[10];函式宣告:void fuc(int
Time of Update: 2018-12-06
C語言/C++怎樣產生隨機數:這裡要用到的是rand()函數, srand()函數,C語言/C++裡沒有內建的random(int number)函數。 (1) 如果你只要產生隨機數而不需要定義範圍的話,你只要用rand()就可以了:rand()會返回一隨機數值, 範圍在0至RAND_MAX 間。RAND_MAX定義在stdlib.h, 其值為2147483647。 例如:#include<stdio.h> #include<stdlib.h>
Time of Update: 2018-12-06
網上看到的都是是整行讀入,然後處理!方法讀入到string類型的一個對象,然後替換string中的“,”為空白格或者其他想要的分隔字元;然後使用修改後的string初始化一個stringstream,逐個的將資料讀入到目標的對象中去。2011.6.25看到有好心人給我回複,說可以使用strtok()函數,所以我就尋找了關於這個函數的相關知識,學習學習~ 原型:char *strtok(char *s, char
Time of Update: 2018-12-06
http://www.cnblogs.com/nawind/articles/1339991.htmlhttp://blog.csdn.net/qiuqiu173/article/details/1968299struct MyStruct { double dda1; char dda; int type };sizeof(MyStruct)=16
Time of Update: 2018-12-06
連結器ld//link.c#include <stdio.h>#include <stdlib.h>int main(){ printf("%f\n", square(0.3)); system("pause");return 0;}//square.cdouble square(double x){return x*x;}直接使用ld連結目標檔案,輸出如下:D:\C陷阱與缺陷\test\test>ld link.o
Time of Update: 2018-12-06
(一個學姐提到的問題~)原文連結http://blog.csdn.net/g5dsk/article/details/4775089 #include <iostream> using namespace std; class A { public: A() { cout << "Default constructor is called./r/n"; } A(int ix)
Time of Update: 2018-12-06
const 修飾指標:如果關鍵字const出現在星號*左邊,表示被指物是常量,如果const出現在*右邊表示指標自身是常量, 如果出現在兩邊表示被指物和指標都是常量; const std::vector<int>::iterator iter = vec.begin(); //iter的作用就像是T* const; ++iter;錯誤 std::vector<int>::const_iterator cIter = vec.begin();
Time of Update: 2018-12-06
對象的成員變數的初始化動作發生在進入建構函式本體之前。ABEntry::ABEntry(const std::string& name, const std::list<PhoneNumber>& phones){ theName = name; //這些都是賦值,不是初始化 thePhones = phones; numTimesConsulted =
Time of Update: 2018-12-06
編譯給會為一個空類聲明一個default建構函式、一個copy建構函式、一個copy assignment操作符、和一個解構函式。所有這些都是public且inline:class Empty{};就像是寫了這樣的代碼:class Empty{ Empty(){…} Empty(const Empty& rhs) {…} ~Empty(){…} Empty& operator=(const Empty&
Time of Update: 2018-12-06
為了駁回編譯器自動提供的功能, 可將相應的成員函式宣告為private並不予實現。如果在成員函數或friend函數調用這些, 串連時會報錯。將串連錯誤移至編譯期是可能的,設定一個專門為了防止copying動作的base classs:class Uncopyable{protected: //允許derived物件建構和析構 Uncopyable(){} ~Uncopyable(){}private:
Time of Update: 2018-12-06
http://www.cppblog.com/abilitytao/archive/2011/10/20/77699.htmlC++標準庫簡介(轉) C++標準庫的所有標頭檔都沒有副檔名。C++標準庫的內容總共在50個標準標頭檔中定義,其中18個提供了C庫的功能。 <cname>形式的標準標頭檔【 <complex>例外】其內容與ISO標準C包含的name.h標頭檔相同,但容納了C++擴充的功能。在
Time of Update: 2018-12-06
最近在整理C++知識的時候,突然想到如何在C++中實現建構函式調用建構函式的問題,常見的錯誤是按照如下方式來調用: 1: #include 3: class Test 4: { 5: public: 6: int m_a; 8: Test(int a) 9: {10: m_a = a;11: }13: Test()14: {15: Test(1);16: }17: };19:
Time of Update: 2018-12-06
什麼是介面,介面是一種機制,制定了類應該實現的方法以及這些方法的特徵標,如果IAnimal是一個介面,而CDog是一個事先了介面IAnimal的類,則CDog必須實現介面的聲明和方法.因此,介面相當於一種約定,而實現介面的類必須遵守約定C++如何?介面呢C++介面是只包含純虛函數的抽象基類.繼承抽象基類的類必須實現它聲明的純虛函數,並且採用指定的特徵標.倘若衍生類別也是抽象類別的話,就是上一遍"繼承純虛函數"就沒有全部實現基類的純虛函數了,實現了部分. 作者: 林羽飛揚出處:http://www
Time of Update: 2018-12-06
關於三個SDK函數: WinExec, ShellExecute,CreateProcess 的其他注意事項:【1】定義標頭檔必須定義以下標頭檔:#include <windows.h>【2】定義路徑C++中所表示的路徑要用 " \\ "而不是平常所用的" \ ",所以以上三個函數表示路徑都為:disk:\\Directory\\...\\File nameWinExec("D:\\Program
Time of Update: 2018-12-06
摘自<<C和指標>>3.23 int *a;int* a;兩者意思相同且後者看上去更為清楚:a被聲明為類型為 int* 的指標. 但是,這並不是一個好技巧,原因如下:int* b, c, d;人們很自然地以為這條語句把所有三個變數聲明為指向整形的指標, 但事實上並非如此. 我們被它的形式愚弄了. 星號實際上是運算式 *b 的一部分, 只對這個標識符有用. b 是一個指標, 但其餘兩個變數只是普通的整形. 要聲明三個指標, 正確的語句如下:int *b, *c, *d;
Time of Update: 2018-12-06
轉自:http://hi.baidu.com/why0813/blog/item/850ea46eecf658db80cb4a6a.html C++標準庫非常大。在C++標準中,關於標準庫的規格說明佔了密密麻麻300多頁,這還不包括標準C庫,後者只是
Time of Update: 2018-12-06
以下樣本中定義了一個class test, 重載了<, +, +=, =, ==, <<, >>等符號:#include<iostream> #include<vector> using namespace std; class test{ public: int v; /*建構函式*/ test():v(0){} test(const int &a):v(a){} test(const
Time of Update: 2018-12-06
轉自:http://bbs.chinaunix.net/viewthread.php?tid=936821================================================== Keywords: String Literal, Object, Array, Lvalue Author: whyglinux<whyglinux AT gmail DOT com> Date: 2007-05-16 ==================
Time of Update: 2018-12-06
轉自:http://www.cnblogs.com/growup/archive/2012/01/07/2315557.html 一 C++標準庫與STL(標準模板庫)的聯絡、區別STL即標準模板庫(Standard Template Library),它包括6大類組件:演算法(Algorithm)、容器(Container)、空間分配器(Allocator)、迭代器(Iterator)、函數對象(Functor)、適配器(Adapter)。qin註:按侯捷《STL源碼剖析》:6大組件的關係是:
Time of Update: 2018-12-06
轉 自:http://www.cnblogs.com/rocketfan/archive/2009/10/02/1577361.html 1. 編譯單元:一個.cc或.cpp檔案作為一個編譯單元,產生.o。2. 普通資料類型的定義、聲明,函數的定義、聲明(類函數是一樣的)。extern int x; // 變數是聲明,並未實際分配地址,未產生實際目標代碼 void print(); // 函式宣告, 未產生實際目標代碼如 int x; int x = 3 ; void print()