Pages

2010年12月31日 星期五

C++多重繼承

下面為C++多重繼承的網路經典範例。 //程序作者:管寧 //站點:www.cndev-lab.com //所有稿件均有版權,如要轉載,請務必著名出處和作者 #include <iostream> using namespace std; class Vehicle { public:     Vehicle(int weight = 0) { Vehicle::weight = weight;         cout << "載入Vehicle類構造函數" << endl;     }     void SetWeight(int weight) {         cout << "重新設置重量" <<...

Apache Tomcat Native library which allows optimal performance

利用用Eclipse 和tomcat 6.0,運行tomcat時候出現如下問題: tomcat6.0 The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path 這是一個跟ARP有關的問題 APR(Apache portable Run-time libraries,Apache可移植運行庫), 主要為上層的應用程序提供一個可以跨越多操作系統平台使用的底層支持接口庫。在早期Apache版本中,應用程序本身必須能夠處理各種具體操作系統平台的細節,並針對不同的平台調用不同的處理函數。隨著Apache的進一步開發,Apache組織決定將這些通用的函數獨立出來並發展成為一個新的項目。這樣,APR的開發就從Apache中獨立出來,Apache僅僅是使用APR而已。目前APR主要還是由Apache使用,不過由於APR的較好的移植性,因此一些需要進行移植的C程序也開始使用APR,開源項目比如Flood...

2010年12月30日 星期四

【CMD】大量刪除指令

Windows下,[cmd]大量刪除指令  [delDir.bat] @echo 移動到該磁區 c: @echo 刪除資料夾下所有檔案(包含該資料夾本身) rmdir C:\temp\source\ /s/y @echo 建立資料夾 md C:\temp\source\ rmdir 指令參數 [rmdir [folder] /s /q /s : 刪除指定目錄和所有子目錄,包括任何文件。. /q : 刪除目錄無確認。 /? : 顯示幫助在命令提示。 ...

【CMD】大量複製指令

Windows下,大量複製指令   [movefile.bat] @echo 移動到該磁區 c: @echo 移動磁碟中一個檔案 copy C:\temp\source\test.java C:\project\source\ @echo 移動磁碟中資料夾內所有檔案包含樹狀結構(子資料夾下的檔案) xcopy C:\temp\source\ C:\project\source\ /s/y @echo 暫停指令 pause /S 複製每個目錄及其包含的子目錄。 /D 複製發生變更的檔案。 /Y 所有覆蓋的詢問都回答 YES 完整的 參數內容(從xcopy /?得知): XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/G] [/H] [/R] [/T] [/U] [/K]...

2010年10月2日 星期六

Java String 依照單字出現次數/頻率高的依序印出

功能: 依照每個單字出現的次數,由大到小,排列印出。 假設: String oriString = "This is a book. That is a pencil" 輸出: is 出現 2 次 a 出現 2 次 This 出現 1 次 That 出現 1 次 book 出現 1 次 pencil 出現 1 次 程式碼: import java.util.regex.*; import java.util.*; public class StringSort { public static void main(String[] args){ String oriString = "This is a book. That is a pencil."; Pattern p = Pattern.compile("\\w[^\\.\\s]*"); Matcher m = p.matcher(oriString); Set<string> sortVerb...

Linking-List Implement

[轉載] from: http://www.cnblogs.com/oomusou/archive/2008/03/22/1117686.html Abstraction 使用C語言簡單的實現linked list,並用C++的std::vector實作出相同的功能作比較。 Introduction 學習資料結構,第一個要學的就是linked list,本文示範最簡單的linked list實現,包含建立與顯示,可把它當成linked list的標準範本,畢竟步驟都差不多。 一個基本的問題:為什麼需要linked list?若要將大量資料存到記憶體,你會想到什麼?第一個想到的就是array,但C語言是個靜態語言,array必須事先宣告大小,這樣compiler才能進行最佳化,若到時候沒用這麼多記憶體,就白白浪費記憶體了。或許你會說array可以配合malloc()變成動態array,但前提是你必須告訴malloc()要建立多大的array,若連要建立多大的陣列也不確定,而是在run-time看有多少資料就建立多大,這時連malloc()的動態array也不能用了,此時就得靠linked...

C語言指標範例(指標++)

C語言中最令初學者人頭大的指標,其實很容易記錯 指標的運算元順序是由右到左(書上寫的),實際來測試一下 #include<stdio.h> int data[2] = {100,200}; int moredata[2] = {300,400}; int main(void){ int * p1, * p2, * p3; p1 = p2 = data; p3 = moredata; printf(" *p1 = %d, *p2 = %d, *p3= %d\n", *p1, *p2, *p3); printf(" *p1 = %d, *p2 = %d, *p3= %d\n", *p1++, *++p2, (*p3)++); printf(" *p1 = %d, *p2 = %d, *p3= %d\n", *p1, *p2, *p3); //括號測試 printf("It is equal result...\n"); p1 = p2 = data; ...

C/C++[微小位元][數字&數字]

最近,因為面試的關係,想把一些東西弄清楚,所以做了一些測試: 以下是微小位元的測試,實際是就是二進位運算啦,考是算錯(怪怪) #include<stdio.h> int main(void){ int a = 44; int b = 55; int c = 33; int d = -20; printf("uni-micro operator: \n"); printf("a & b = %d\n", a & b); printf("b & c = %d\n", b & c); printf("c & d = %d\n", c & d); printf("b & b = %d\n", b & b); printf("a | b = %d\n", a | b); printf("double-micro operator: \n"); printf("a &&...

2010年2月2日 星期二

解決C/C++中的multiple definition of問題

範例: main.cpp #include "global.h" int Main(....) { ... } file_1.cpp #include "global.h" .... file_1.cpp #include "global.h" global.h中寫有所有的全局變量及其初始化值和函數聲明 在編譯的時候就會出錯: first defined here multiple definition of 原因是因為在多次包含global.h時重複定義了變量和函數。 解決方法:  方法一: 在global.c(或.cpp) 中聲明變量(不初始化),然後頭文件global.h中在所有的變量聲明前加上extern 如 extern int flag; 然後在其他需要使用全局變量的cpp文件中包含.h 文件而不要包含.cpp 文件。編譯器會為global.cpp 生成目標文件,然後連接時,在使用全局變量的文件中就會連接到此文件。  範例: Declare.h: #ifndef...

2010年1月26日 星期二

vector傳遞/宣告(struct/物件)以及iterator 範例

轉載[http://www.cnblogs.com/oomusou/archive/2008/08/01/vector_struct.html] Abstract 一個很常見的需求:『將struct塞進vector』,在C++該怎麼做呢? Introduction 使用環境:Visual C++ 9.0 / Visual Studio 2008 由於vector只允許一個欄位,所以才會想將struct塞進vector,以彌補vector的不足。 struct_in_vector.cpp / C++ /* (C) OOMusou 2008 http://oomusou.cnblogs.com Filename : struct_in_vector.cpp Compiler : Visual C++ 9.0 / Visual Studio 2008 Description : Demo how to insert struct in vector Release...

vector內元件刪除

 C++中 vector內元素刪除的方法分為兩個~ 方法1: vector<AA>::iterator ite; for ( ite = vaa.begin(); ite != vaa.end(); ) { if (find(intList.begin(), intList.end(),ite->n) != intList.end()) vaa.erase(++ite); else ++ite; } 方法2: vector<AA>::iterator ite = vaa.begin(); for (ite = vaa.begin(); ite != vaa.end(); ++ite ) { if (find(intList.begin(), intList.end(),ite->n) != intList.end()) vaa.erase(ite); } 當vector內是物件或是struct時,以上的方法可能會有錯誤,這是因為當 erase時,iterator就會失效,因此可以用下面的方式解決 方法3: struct...

2010年1月23日 星期六

Java判斷作業系統與檔案路徑

如何在java程式中判斷幕前作業系統是何種作業系統 以下位範例程式: public class OSValidator { public static void main(String[] args) { if (isWindows()) { System.out.println("This is Windows"); } else if (isMac()) { System.out.println("This is Mac"); } else if (isUnix()) { System.out.println("This is Unix or Linux"); } else { System.out.println("Your OS is not support!!"); } } public...