?? 09d1.cpp
字號:
/*
NIIT 《C++ & CGI PROGRAMMING &SCRRIPTING》 Skill Base
教材P9.8 9.D.1
審核:周永 Laozhou@swpi.edu.cn 23:58 2004-10-18
測試環境:Microsoft Windowsn 2000(VC++);Red Hat Linux 7.3;Red Hat Linux 9.0
*/
#include <iostream>
#include <string>
using namespace std;
class String
{
private:
char *str;
int check()
{
if (str == NULL)
return 0;
else
return 1;
}
public:
String()
{
str = 0;
}
String(char *inString)
{
str = new char[strlen(inString)+1];
strcpy(str,inString);
}
void replace(char search, char repl)
{
if(check() == 0)
{
throw "NULL pointer exception";
}
int counter;
for(counter = 0; str[counter] != '\0'; counter++)
{
if(str[counter] == search)
{
str[counter] = repl;
}
}
}
void display()
{
cout << str;
}
};
int main()
{
String strObject; //The Object Does Not Contain Anything
try
{
strObject.replace('+',' '); //The replace Function Raises An Exception
strObject.display();
}
catch(char *message)
{
cout << "Exception : " << message << endl;
}
catch(...)
{
cout <<"Unknown Exception!" <<endl;
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -