标签:space stream pre out 重要 default break ase case
#include<iostream> using namespace std; int str_cpy(char * to, char *from) { if (from == NULL) { return 1; } if (to == NULL) { return 2; } if (*from == ‘a‘) { return 3; } while (*from != ‘\0‘) { *to = *from; to++; from++; } *to = ‘\0‘; return 0;//这句话只管重要,如果不返回零的话,下面的case中就会执行default的命令行。 } int main() { int a = 0; char buf1[28] = "dfewgs"; //char *buf2 = new char[strlen(buf1)+1]; char buf2[128] = { 0 }; a = str_cpy(buf2, buf1); if(a != 0) { switch (a) { case 1: break; case 2: break; case 3: cout << "case3\n"; break; default: cout << "default\n"; break; } } cout << buf2 << endl; system("pause"); }
标签:space stream pre out 重要 default break ase case
原文地址:http://www.cnblogs.com/xiaochige/p/6820532.html