编译没错---但运行不出来,WHY?
//把IP的每个段分别存储在另外4个字符串中#include <iostream>
#include <string>
using namespace std;
int main()
{string std="123.121.123.87";
char ch1[3],ch2[3],ch3[3],ch4[3];
int i,j,count;
i=0;
j=0;
count=0;
while(std[i])
{if(std[i]=='.')
{count++;i++;j=0;}
switch(count)
{case 0:ch1[j]=std[i];j++;break;
case 1:ch2[j]=std[i];j++;break;
case 2:ch3[j]=std[i];j++;break;
case 3:ch4[j]=std[i];j++;break;
}
i++;
}
for(i=0;i<3;i++)
cout<<ch1[i];
cout<<endl;
for(i=0;i<3;i++)
cout<<ch2[i];
cout<<endl;
for(i=0;i<3;i++)
cout<<ch3[i];
cout<<endl;
for(i=0;i<3;i++)
cout<<ch4[i];
cout<<endl;
return 0;
}
[此贴子已经被作者于2006-4-11 7:57:27编辑过]