Time of Update: 2018-12-04
#include <iostream>#include <string>using namespace std;class A{public:A(){cout << "creat A" << endl;scc();}virtual void scc(){cout << "scc from A" << endl;}virtual ~A(){cout << "delete A" <<
Time of Update: 2018-12-04
#ifdef __cplusplus extern "C" { #endif //一段代碼 #ifdef __cplusplus } #endif 這樣的代碼到底是什麼意思呢?首先,__cplusplus是cpp中的自訂宏,那麼定義了這個宏的話表示這是一段cpp的代碼,也就是說,上面的代碼的含義是:如果這是一段cpp的代碼,那麼加入extern "C"{和}處理其中的代碼。 要明白為何使用extern
Time of Update: 2018-12-04
1. 用預先處理指令#define 聲明一個常數,用以表明1年中有多少秒(忽略閏年的問題)answer: SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL注釋: 我這裡想看到幾件事情:1, #define
Time of Update: 2018-12-04
很多庫函數,特別是那些與作業系統有關的,當執行失敗時會通過一個名稱為errno的外部變數,通知程式該函數調用失敗。下面的代碼利用這一特性進行錯誤處理:errno = 0;//*調用庫函數*/if(errno)
Time of Update: 2018-12-04
單項鏈表插入操作,我想應該是最基礎不過的東西,今天要介紹的是比較簡潔的版本。需求:插入一個node到鏈表的正確位置,當前鏈表中節點的value已經按照由小到大進行排列。傳統的插入操作:int insertNode(Node** rootp,int new_value){Node *current;Node *previous;Node *new;current = *rootp;previous = NULL;while(current != NULL &&
Time of Update: 2018-12-04
建立一個檔案叫a.h,它包含了聲明:extern int i;需要用到外部對象filename的每個C原始碼都應該加上這樣一個語句:#include “a.h”最後我們選擇一個C源檔案,在其中給出i的初始值,我們稱這個檔案為a.c#include <stdio.h>#include "a.h"int i=8;int main(void){ printf("%d\n",i); return
Time of Update: 2018-12-04
#include <stdio.h>#define peach inttypedef int banana;int main(void){ unsigned peach a; unsigned banana b; return 0;}上面的代碼中,unsigned banana b;該行編譯會出現錯誤。因為typedef是一種徹底的“封裝”類型,而#define只是簡單的文本替換。再看,#include
Time of Update: 2018-12-04
今天為了徹底搞定一個關於c中數組初始化和聲明不同情況下,比如只聲明一個數組char str[20];那麼這str裡面是什麼內容呢?我用vc6++,debug下看到都是-56餓asc碼,後來請教了一個華為的大牛,他說 按照理論來說裡面的內容都是有可能的,這和叫做“髒記憶體”或者叫做“野數組”。好了第一個問題搞懂了。 第二個問題
Time of Update: 2018-12-04
昨晚睡前看書的時候看到C語言裡面對變數的定義很有意思,比如auto static register extern這些關鍵字。 最感興趣的莫過於那個局部的static定義的變數。 根據書中描述局部static的變數 等價於 全域的非靜態變數。一般我們知道全域的變數在函數結束後再次調用的時候就會改變的,但是局部的靜態變數 總覺得這樣來很BT。經過驗證的確是這樣的效果。 看代碼:先來個局部的靜態變數 #include <stdio.h>int main(){int
Time of Update: 2018-12-04
1:類似junit的斷言,只是在assert中的斷言,如果不滿足的話就程式退出。比如#include <assert.h>int main(void){ assert(6 < 5); system("pause"); return 0;}在執行到assert(6 < 5);的時候因為不滿足斷言,於是程式退出。如果不想讓assert(6 < 5)起作用,就在最上面添加宏定義#define NDEBUG要添加在#include
Time of Update: 2018-12-04
public static string getContent(string Url, string encode) { string strResult = ""; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); //聲明一個HttpWebRequest請求
Time of Update: 2018-12-04
記得在剛學delphi時,第一個程式就是一個播放flash的小軟體,當時好開心. 今天,我在C#中實現了這個小程式. 播放Flash動畫的原理是引用Flash的dll.用它來播放. 現在工具箱中添加這個控制項: 1.工具箱上點滑鼠右鍵,出現菜單,選擇 "Choose Items...",在出現的視窗選擇"Com components"選項卡,選擇Shockwave Flash
Time of Update: 2018-12-04
我也是在網上看到的,沒什麼可說的,直接看代碼吧:using System;using System.Runtime.InteropServices;public struct RASCONN{public int dwSize;public IntPtr hrasconn;[MarshalAs(UnmanagedType.ByValTStr, SizeConst=257)]public string szEntryName;[MarshalAs(UnmanagedType.ByValTStr,
Time of Update: 2018-12-04
(一)INIFile.cs using System;using System.Runtime.InteropServices;using System.Text;namespace CreateWebDir{ /// <summary> /// INIFile 的摘要說明。 /// </summary> public class INIFile { public string path; public INIFile(string
Time of Update: 2018-12-04
System.IO.FileStream fs=new System.IO.FileStream(lstFile.Text,System.IO.FileMode.Open,System.IO.FileAccess.Read); long lngPos=fs.Seek(-128,System.IO.SeekOrigin.End); byte[] bInfo=new
Time of Update: 2018-12-04
1、DateTime 數字型 System.DateTime currentTime=new System.DateTime(); 1.1 取當前年月日時分秒 currentTime=System.DateTime.Now; 1.2 取當前年 int 年=currentTime.Year; 1.3 取當前月 int 月=currentTime.Month; 1.4 取當前日 int
Time of Update: 2018-12-04
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Net;namespace XcDownLoadFile{ public class DownLoadFile { /// /// 下載檔案方法 /// /// 檔案儲存路徑和檔案名稱 ///
Time of Update: 2018-12-04
泛型這一話題是面試時經常問到的問題,經過自己回頭查閱資料實際操作之後,整理如下:泛型的出現是為了避免頻繁的裝箱和拆箱操作,也節省了頻繁的開闢記憶體的操作。以下是Dictionary的使用。Dictionary就是一組索引值對集合類型,可以存放任何資料類型,比如int,string,object等。 Dictionary<int, string> dictionary; dictionary = new Dictionary<int,
Time of Update: 2018-12-04
在實際開發中,web service的使用變得日益普及,特別是在移動互連網上,移動終端響應與請求資料往往是串連web service得到的。往往web
Time of Update: 2018-12-04
一般情況下,.NET使用稀缺資源時,比如資料庫連接、視窗、繪圖物件,最好使用資源後及時時釋放掉該資源,這樣會提高程式運行效率,減少資源消耗。雖然說,C#中會有記憶體回收(System.GC.Collect()) ,但是稀缺資源還是越早釋放越好。以下是最優的使用稀缺資源時的代碼架構如下:try{using(SqlConnection conn=new