命名空间:
#include<iostream>
#include<string>
using namespace std;
namespace zhang{
void show(){
cout<<"hello,welcome to use namespace zhang"<<endl;
}
}
namespace li{
void showtoo(){
cout<<"use namespace rencheng showone"<<endl;
}
}
using namespace zhang;
using namespace li;
int main(){
show();
showtoo();
return 0;
}
异常:
#include<iostream>
#include<string>
using namespace std;
class Bad{
public:
Bad(string s){
name=s;
}
void show(){
cout<<name<<endl;
}
private:
string name;
};
int to_int(char a){
if(a=='o')throw Bad("这是一个异常");
return (int)a;
}
int main(){
int c='o';
try{
int x=to_int(c);
}catch(Bad b){
b.show();
}
return 0;
}
#include<iostream>
#include<string>
using namespace std;
void f(){
throw "Boom";
}
int main(){
try{
f();
}catch(const char* s){
cout<<"caught "<<s<<endl;
}
return 0;
}