vc 2005下的問題

看板Programming作者時間17年前 (2008/03/01 15:32), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
我用dev-c++編輯以下程式是ok 可是我用c++ 2005 express編輯卻會出錯.. 我先把程式碼寫出來好了 其實這參考了 http://caterpillar.onlyfun.net/Gossip/CppGossip/CustomExceptionClass.html 程式碼: // exception5.cpp : 定義主控台應用程式的進入點。 // #include "stdafx.h" #include <iostream> using namespace std; class DivideByZero { public: DivideByZero(int n, int d) : num(n), denom(d), message("Divide by zero") {} ~DivideByZero() {} int getNumerator() {return num;} 踠 int getDenominator() {return denom;}C\蠊 string getMessage() {return message;} private: int num; int denom; string message; }; int _tmain(int argc, _TCHAR* argv[]) //vc6: int main() { int x = 5; int y = 0; int result; try { if (y == 0) { throw DivideByZero(x, y); } result = x/y; } catch (DivideByZero e) { cout << e.getMessage() << endl; cout << "Numerator: " << e.getNumerator() << endl; cout << "Denominator: " << e.getDenominator() << endl; } cout << "Goodbye" << endl; return 0; } 問題出在 cout << e.getMessage() << endl; 錯誤訊息如下: c:\program files\microsoft visual studio 8\vc\include\ostream(656): 可 能是 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' 請問我該如何修改呢? 另外想請問,是否有推薦的網站、網頁介紹c++的例外處理呢? 我發現C++的例外處理讓我好意外 我不知該怎麼練習 謝謝 -- ┌─────KKCITY─────┐ KKBOX 可立刻 聽音樂 bbs.kkcity.com.tw 想聽什麼歌 通通不必等 └──From:140.109.123.38 ──┘ http://www.kkbox.com.tw ■■ --

03/01 15:54, , 1F
e.getMessage().c_str() ?
03/01 15:54, 1F

03/03 00:46, , 2F
#include <string>
03/03 00:46, 2F
文章代碼(AID): #17oGPs00 (Programming)
文章代碼(AID): #17oGPs00 (Programming)