- //c++版
- #include<string>
- #include<iostream>
- #include<exception>
- using namespace std;
- int main()
- {
- try{
- string p1("this is p1");
- string p2("this is p2");
- string p3("this is p3");
- cout << p1 << endl;
- cout << p2 << endl;
- cout << p3 << endl;
- }
- catch(...){
- return -1;
- }
- return 0;
- }
- //c版
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int main()
- {
- char *p1;
- char *p2;
- char *p3;
- int result=-1;
- do{
- p1=malloc(0x10 * sizeof(char));
- if(NULL == p1)break;
- strcpy(p1,"this is p1");
- p2=malloc(0x10 * sizeof(char));
- if(NULL == p2)break;
- strcpy(p2,"this is p2");
- p3=malloc(0x10 * sizeof(char));
- if(NULL ==p3)break;
- strcpy(p3,"this is p3");
- printf("%s\n%s\n%s\n",p1,p2,p3);
- result=0;
- }while(0);
- if(NULL != p1)free(p1);
- if(NULL != p2)free(p2);
- if(NULL != p3)free(p3);
- return result;
- }