我怎样才能加上?’;“警告信息”;我的节目? 我用C++编写了一个项目的程序;但是,我不能在我的算法中添加“返回警告消息”

我怎样才能加上?’;“警告信息”;我的节目? 我用C++编写了一个项目的程序;但是,我不能在我的算法中添加“返回警告消息”,c++,arrays,oop,C++,Arrays,Oop,我的爱 #include<iostream> #include<conio.h> using namespace std; const int k=100; class safearay{ int arr[k]; int getel(int index){ if(index>-1 && index<k) return arr[index];}}; void main(void) { cout<<"

我的爱

#include<iostream>

#include<conio.h>

using namespace std;

const int k=100;

class safearay{
    int arr[k];

    int getel(int index){ if(index>-1 && index<k) return arr[index];}};

void main(void)
{
    cout<<"-------------------------------------------------------------------------------\n"<<endl;

    safearay safea1; int temp=23456;

    for{
    safea1.putel(7, temp);  temp=safea1.getel(7);
    cout<<temp;
    cout<<"\n\n !Press k to continue."<<endl<<endl;
    }while(getch()=='k');
}
#包括
#包括
使用名称空间std;
常数int k=100;
班级安全{
int-arr[k];

int getel(int index){if(index>-1&&index一种方法是返回一个标志,指出
putel
函数出错,并在main中打印错误

bool putel(int index, int value){ 

    if(index <= -1 || index == 10 || index > LIMIT) {//the conditions that are invalid
       return false;
    }

     arr[index]=value;
     return true;
}
boolputel(int索引,int值){
if(索引限制){//无效的条件
返回false;
}
arr[指数]=数值;
返回true;
}
主要是这样的

 do{
     if(!safea1.putel(7, temp)){
        cout<<"Insert failed "<<endl; //Your warning message
     } else {
       temp=safea1.getel(7);
       cout<<temp;
       cout<<"\n\n !Press k to continue."<<endl<<endl;
   } while(getch()=='k');
do{
如果(!safea1.putel(7,温度)){

cout一种方法是返回一个标志,指出putel
函数出现了错误,并在main中打印错误

bool putel(int index, int value){ 

    if(index <= -1 || index == 10 || index > LIMIT) {//the conditions that are invalid
       return false;
    }

     arr[index]=value;
     return true;
}
boolputel(int索引,int值){
if(索引限制){//无效的条件
返回false;
}
arr[指数]=数值;
返回true;
}
主要是这样的

 do{
     if(!safea1.putel(7, temp)){
        cout<<"Insert failed "<<endl; //Your warning message
     } else {
       temp=safea1.getel(7);
       cout<<temp;
       cout<<"\n\n !Press k to continue."<<endl<<endl;
   } while(getch()=='k');
do{
如果(!safea1.putel(7,温度)){

cout一种方法是返回一个标志,指出putel
函数出现了错误,并在main中打印错误

bool putel(int index, int value){ 

    if(index <= -1 || index == 10 || index > LIMIT) {//the conditions that are invalid
       return false;
    }

     arr[index]=value;
     return true;
}
boolputel(int索引,int值){
if(索引限制){//无效的条件
返回false;
}
arr[指数]=数值;
返回true;
}
主要是这样的

 do{
     if(!safea1.putel(7, temp)){
        cout<<"Insert failed "<<endl; //Your warning message
     } else {
       temp=safea1.getel(7);
       cout<<temp;
       cout<<"\n\n !Press k to continue."<<endl<<endl;
   } while(getch()=='k');
do{
如果(!safea1.putel(7,温度)){

cout一种方法是返回一个标志,指出putel
函数出现了错误,并在main中打印错误

bool putel(int index, int value){ 

    if(index <= -1 || index == 10 || index > LIMIT) {//the conditions that are invalid
       return false;
    }

     arr[index]=value;
     return true;
}
boolputel(int索引,int值){
if(索引限制){//无效的条件
返回false;
}
arr[指数]=数值;
返回true;
}
主要是这样的

 do{
     if(!safea1.putel(7, temp)){
        cout<<"Insert failed "<<endl; //Your warning message
     } else {
       temp=safea1.getel(7);
       cout<<temp;
       cout<<"\n\n !Press k to continue."<<endl<<endl;
   } while(getch()=='k');
do{
如果(!safea1.putel(7,温度)){

cout您可以使用
throw
,例如:

class safearray
{
public:
    void putel(int index, int value) { check_index(index); arr[index] = value;}
    int getel(int index) const { check_index(index); return arr[index];}

private:
    void check_index(int index) const
    {
        if (index < 0 || LIMIT <= index) {
            throw std::out_of_range("bad index " + std::to_string(index) + " for safearray");
        }
    }
private:
    int arr[LIMIT];
};
类安全数组
{
公众:
void putel(int index,int value){check_index(index);arr[index]=value;}
int getel(int index)const{check_index(index);返回arr[index];}
私人:
无效检查索引(整数索引)常量
{

如果(索引<0 | |限制,您可以使用
throw
,类似于:

class safearray
{
public:
    void putel(int index, int value) { check_index(index); arr[index] = value;}
    int getel(int index) const { check_index(index); return arr[index];}

private:
    void check_index(int index) const
    {
        if (index < 0 || LIMIT <= index) {
            throw std::out_of_range("bad index " + std::to_string(index) + " for safearray");
        }
    }
private:
    int arr[LIMIT];
};
类安全数组
{
公众:
void putel(int index,int value){check_index(index);arr[index]=value;}
int getel(int index)const{check_index(index);返回arr[index];}
私人:
无效检查索引(整数索引)常量
{

如果(索引<0 | |限制,您可以使用
throw
,类似于:

class safearray
{
public:
    void putel(int index, int value) { check_index(index); arr[index] = value;}
    int getel(int index) const { check_index(index); return arr[index];}

private:
    void check_index(int index) const
    {
        if (index < 0 || LIMIT <= index) {
            throw std::out_of_range("bad index " + std::to_string(index) + " for safearray");
        }
    }
private:
    int arr[LIMIT];
};
类安全数组
{
公众:
void putel(int index,int value){check_index(index);arr[index]=value;}
int getel(int index)const{check_index(index);返回arr[index];}
私人:
无效检查索引(整数索引)常量
{

如果(索引<0 | |限制,您可以使用
throw
,类似于:

class safearray
{
public:
    void putel(int index, int value) { check_index(index); arr[index] = value;}
    int getel(int index) const { check_index(index); return arr[index];}

private:
    void check_index(int index) const
    {
        if (index < 0 || LIMIT <= index) {
            throw std::out_of_range("bad index " + std::to_string(index) + " for safearray");
        }
    }
private:
    int arr[LIMIT];
};
类安全数组
{
公众:
void putel(int index,int value){check_index(index);arr[index]=value;}
int getel(int index)const{check_index(index);返回arr[index];}
私人:
无效检查索引(整数索引)常量
{

如果(index<0 | | LIMIT)你可以使用
throw
?我如何使用throw?你有什么建议吗?你可以使用
throw
?我如何使用throw?你有什么建议吗?你可以使用
throw
?我如何使用throw?你有什么建议吗?