#ifndef STR_H
#define STR_H
#include<iostream>
#include<string>
using namespace std;
class Error{};
class OUT{};
class STR{
char *p;
int len;
public:
STR(){p=NULL;len=0;}
~STR(){delete [] p;p=NULL; }
void show()throw(Error){
try{if(p)printf("%s\n",p);else throw(Error());}
catch(Error){cout<<"str is null"<<endl;}
}
const char & at(int idex){try{if(idex>len||idex<0)throw(OUT());else return p[idex];}catch(OUT){cout<<"int idex is out of size,index must >=0and <length"<<endl;}}
};
#endif // STR_H
主函数main.cpp中
STR str=STR();
str.show();
cout<<str.at(3);