Time of Update: 2018-12-03
/************************************************* Function: get_ipaddrDescription: get ip addr Input: net_dev ipaddrOutput: Return: 0 sucess -1 failedOthers: *************************************************/int get_ipaddr(const char *net_dev,
Time of Update: 2018-12-03
C/C++中near和far的區別 關鍵字near和far受目標電腦體繫結構的影響。目前編程中使用不多。 near關鍵字建立一個指向可定址記憶體低端部分的目標指標。這些指標佔用記憶體的單一位元組,並且他們能夠指向的記憶體單元被限制到256個位置,通常是在 0x0000~0x00ff範圍中。 int near * ptr; far關鍵字建立一個能夠指向記憶體中任何資料的指標: char far * ptr; near
Time of Update: 2018-12-03
12-3 代碼 /*服務端*/#include<sys/types.h>#include<sys/socket.h>#include<string.h>#include<sys/unistd.h>#include<netinet/in.h>#define MAXSIZE 80#define MYPORT 3490#define BACKLOG 10#define BUFSIZE 100 void main(){ int
Time of Update: 2018-12-03
C語言中的類類比(C++編程思想) 在物件導向的語言裡面,出現了類的概念。這是編程思想的一種進化。所謂類:是對特定資料的特定操作的集合體。所以說類包含了兩個範疇:資料和操作。而C語言中的struct僅僅是資料的集合。(liyuming1978@163.com) 1.執行個體:下面先從一個小例子看起 #ifndef C_Class #define C_Class struct#endif C_Class A { C_Class A *A_this;
Time of Update: 2018-12-03
1.
Time of Update: 2018-12-03
一、開發步驟 1)vi helloworld.c 2)gcc helloworld.c -ohelloworld 3)./helloworld二、第一個unix c程式 #include <stdio.h>int main(){ printf("helloworld,we like zhangzetian \n "); return 0;}解釋 1)#include <stdio.h>
Time of Update: 2018-12-03
優先順序操作符描述例子結合性1()[]->.::++--調節優先順序的括弧操作符數組下標訪問操作符通過指向對象的指標訪問成員的操作符通過對象本身訪問成員的操作符範圍操作符後置自增操作符後置自減操作符(a + b) / 4;array[4] = 2;ptr->age = 34;obj.age = 34;Class::age = 2;for( i = 0; i < 10; i++ ) ...for( i = 10; i > 0; i-- ) ...從左至右2!~++---+*
Time of Update: 2018-12-03
//*********************************************************************//第9題//顯示特殊矩陣//*********************************************************************#include <stdio.h>#include <stdlib.h>#include <math.h>void main(){int array[6
Time of Update: 2018-12-03
string類預設產生的函數有哪些?預設建構函式解構函式拷貝建構函式賦值建構函式 具體實現如下:#include <iostream>using namespace std;class mystring{friend ostream &operator<<(ostream &out,const mystring &s);public:mystring(const char *str=NULL);mystring(const mystring
Time of Update: 2018-12-03
#include <stdio.h>#include <string.h>char *bxy_strstr(const char *s1, const char *s2) {int len2; if (!(len2 = strlen(s2))) {return (char *)s1; }for ( ;*s1; ++s1) { if (*s1==*s2 && strncmp( s1, s2, len2 ) == 0) {return (char *)s1;}
Time of Update: 2018-12-03
#include <iostream>using namespace std; class B {public:int i, j;B(int x = 999) :j(x),i(j){cout << "B::B() invoked\n" << endl;} ~B(){cout << "B::~B() invoked\n" << endl;}};class D : public B {public:D() {cout <<
Time of Update: 2018-12-03
此例也是考試用題,供大家參考。 void binarytree_count(BinaryTree *root){ BinaryTree *node;int count; /*使用輔助隊列,設進隊函數為void in(BinaryTree* Node),出隊函數為BinaryTree *out(),判斷隊列空的函數int isempty()*/ in(root) while(!isempty()) { node=out(); if(node->left!=null)
Time of Update: 2018-12-03
在Windows作業系統中使用DLL有很多優點,最主要的一點是多個應用程式、甚至是不同語言編寫的應用程式可以共用一個DLL檔案,真正實現了資源"共用",大大縮小了應用程式的執行代碼,更加有效利用了記憶體;使用DLL的另一個優點是DLL檔案作為一個單獨的程式模組,封裝性、獨立性好,在軟體需要升級的時候,開發人員只需要修改相應的DLL檔案就可以了,而且,當DLL中的函數改變後,只要不是參數的改變,程式碼並不需要重新編譯。這在編程時十分有用,大大提高了軟體開發和維護的效率。
Time of Update: 2018-12-03
首先看兩個關於const的程式,並且猜測輸出的結果是什嗎? #include <iostream>using namespace std;void main(){const int a = 2;int *b = (int *)&a;*b = 3;cout << a <<endl;cout << (*b) <<endl;} 輸出的是 2 和 3 #include <iostream>using namespace
Time of Update: 2018-12-03
例子是仿照柯元旦的《Android核心剖析》中樣本。在external下建立檔案夾MySurface, 裡面編寫兩個檔案,一個Android.mk,一個Welcome.cppLOCAL_PATH:= $(call my-dir)include $(CLEAR_VARS)LOCAL_SRC_FILES:= \Welcome.cppLOCAL_SHARED_LIBRARIES := \libcutils \libutils \libui \libsurfaceflinger_client
Time of Update: 2018-12-03
(本文摘自c++論壇裡自己文章的回複。)GCC4.5引入這個特性。有興趣的朋友可以編譯測試下面這段代碼:#include <algorithm>#include <cmath>void abssort(float *x, unsigned N) { std::sort(x, x+N, [](float a, float b) { // 注意此處的方括弧 return std::abs(a) <
Time of Update: 2018-12-03
前提:需要使用支援更高gcc版本的第三方NDK包。Android預設版本為:4.4.3。第三方NDK包下載(gcc-4.6.3):http://www.crystax.net/en/android/ndk/7具體使用注意事項請參考此文。本測試主要展示以下內容:1、使用std::function和std::bind實現sigslot機制;2、使用C++11的Lambda運算式3、在C++代碼中回調Java對象的方法例子來源:本測試例子來自網上的一個討論裡的回複,由於看到有lambda運算式,就有了
Time of Update: 2018-12-03
Carbide.c++提示及有用的外掛程式:== 提示 ==詳情如下:1、如何在程式中支援本地語言注釋? 答: 在Carbide.c++菜單,修改當前編輯視窗的Encoding為UTF-8。 在Carbide.c++菜單找: "Edit"->"Set Encoding..."->Other: UTF-8 上面是修改當前已開啟編輯視窗的Encoding。還可以配置當前項目的Encoding, 開啟工程屬性(press ALT+Enter):
Time of Update: 2018-12-03
轉載C語言中如何使用宏C(和C++)中的宏(Macro)屬於編譯器預先處理的範疇,屬於編譯期概念(而非運行期概念)。下面對常遇到的宏的使用問題做了簡單總結。 關於#和##在C語言的宏中,#的功能是將其後面的宏參數進行字串化操作(Stringfication),簡單說就是在對它所引用的宏變數 通過替換後在其左右各加上一個雙引號。比如下面代碼中的宏:#define WARN_IF(EXP) \ do{ if (EXP) \ fprintf(stderr,
Time of Update: 2018-12-03
//==================================================//對const類型的理解class B{public: int b;};class A{public: B *pb; int *pi; A():pb(new B()),pi(new int()) { }};int _tmain(int argc, _TCHAR* argv[]){ const A * pa = new A(); //pa->pb = new B(); //pa->