练习6.10
源文件
1 int main() 2 { 3 try //尝试用下try catch 4 { 5 while (cin >> num1 >> num2) 6 { 7 if (num1 == 999) 8 throw runtime_error("this number may be error!"); 9 exchange_num(&num1, &num2); 10 cout << num1 << " " << num2 << endl; 11 } 12 } 13 catch (runtime_error err) 14 { 15 cout << err.what(); 16 } 17 system("pause"); 18 return 0; 19 }
头文件
1 #ifndef FIRSTHEAD_H 2 #define FIRSTHEAD_H 3 void exchange_num(int *p, int *q); 4 int num1, num2; 5 #endif // !FIRSTHEAD_H
函数定义
1 void exchange_num(int *p, int *q) 2 { 3 int temp; 4 temp = *q; 5 *q = *p; 6 *p = temp; 7 return; 8 }
原文:http://www.cnblogs.com/wuyinfenghappy/p/7274951.html