私は書籍オブジェクトのタイトル、著者、著作権、ISBN番号、およびチェックアウトを取るブッククラスを持っています。しかし、プログラムの実行時にランタイムエラーが発生します。ユーザーがタイトルを入力してEnterを押すと、プログラムはスキップして残りの出力を示し、プログラムを終了させてランタイムエラーを出します。実行時エラー、入力の問題がありますか?
例外をキャッチしようとしましたが、何も取得できませんでした。
コード:問題は何ができるか
#include "std_lib_facilities.h"
class Book{
public:
string what_title();
string what_author();
int what_copyright();
void store_ISBN();
void is_checkout();
private:
char check;
int ISBNfirst, ISBNsecond, ISBNthird;
char ISBNlast;
string title;
string author;
int copyright;
};
string Book::what_title()
{
cout << "Title: ";
cin >> title;
cout << endl;
return title;
}
string Book::what_author()
{
cout << "Author: ";
cin >> author;
cout << endl;
return author;
}
int Book::what_copyright()
{
cout << "Copyright Year: ";
cin >> copyright;
cout << endl;
return copyright;
}
void Book::store_ISBN()
{
bool test = false;
cout << "Enter ISBN number separated by spaces: ";
while(!test){
cin >> ISBNfirst >> ISBNsecond >> ISBNthird >> ISBNlast;
if((ISBNfirst || ISBNsecond || ISBNthird)<0 || (ISBNfirst || ISBNsecond || ISBNthird)>9)
error("Invalid entry.");
else if(!isdigit(ISBNlast) || !isalpha(ISBNlast))
error("Invalid entry.");
else test = true;}
}
void Book::is_checkout()
{
bool test = false;
cout << "Checked out?(Y or N): ";
while(!test){
cin >> check;
if(check = 'Y') test = true;
else if(check = 'N') test = true;
else error("Invalid value.");}
}
int main()
{
Book one;
one.what_title();
one.what_author();
one.what_copyright();
one.store_ISBN();
one.is_checkout();
keep_window_open();
}
わかりません。どんな助けでも感謝しています。
出力例:
タイトル:一つは、カッコウの巣上空 (次の行は、実際に一度出力の間、すべてに離間されていない) 著者:
著作権の年:
ISBN番号をスペースで区切って入力してください:
このアプリケーションでは、異常終了するようにランタイムを要求しています。詳細については、サポートにお問い合わせください。
また、keep_window_open関数とerror関数についても心配はいりません。それらはstd_lib_facilities.hの一部であり、問題を引き起こしていない可能性が最も高いです。エラーは、問題が発生した場合にのみエラーメッセージを出力します。
keep_window_openは何ですか? –
すべての必要なコードを表示する(Alexが示唆しているように、keep_window_open)、プログラムの入出力を表示することで、何が印刷され、何が失敗するのかを正確に見ることができます。 – Tom
私はちょうどstd_lib_facilities.hの簡単なgoogleをやったし、それはコース用です... keep_window_openという関数があります:http://www.stroustrup.com/Programming/std_lib_facilities.h – Tom