打開Dev-C++後,按如下操作創建工程: File->New->Project 得到如下窗口:選擇Console Application (如果你想做GUI界面程序請選擇Windows Application) 創建好後,新建文件(Ctrl+n),一定要選擇添加到工程(得到以下窗口選擇Yes就行了),否則編譯會出錯的(鏈接出錯,我試過了)。 一般一個工程如果有類的話,至少應該有main.cpp和xxx.cpp和xxx.h 這三個文件其中xxx為類文件名: 我的如下: main.cpp [cpp] //main.cpp #include <iostream> #include "demo.h" /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { demo foo1(0); foo1.show(); return 1; } demo.h [cpp] //demo.h #ifndef DEMO_H_ #define DEMO_H_ class demo { private: int var1; public: demo(); demo(int); ~demo(); void show(); }; #endif demo.cpp [cpp] //demo.cpp #include <iostream> #include "demo.h" //constructors demo::demo() { var1 = 0x101; std::cout<<"var1="<<var1<<std::endl; } demo::demo(int input) { this->var1 = input; } void demo::show() { std::cout<<"I am human being, you are computer~~\n"<<std::endl; if(0==this->var1) { std::cout<<"error"<<std::endl; } else std::cout<<"right"<<std::endl; return; } demo::~demo() { }