C++中,以一个特殊字符为标志截取字符串

来源:百度知道 编辑:UC知道 时间:2024/07/04 23:28:15
一个char msg[64]="http://nihao/buhao/aaa:4.3.2:4.3.5";
现在要分别取出
1,http://nihao/buhao/aaa
2,4.3.2
3,4.3.5
谢谢高手帮忙,尽快!!
等待中。。。

我把它分开输出了,你可以根据你的需要自己修改程序的功能:
#include<iostream>
using namespace std;

int main()
{
char msg[64]="http://nihao/buhao/aaa:4.3.2:4.3.5";
int i;
for(i=0;i<strlen(msg);i++)
{
if(msg[i]==':' && (i+1<strlen(msg) && msg[i+1]!='/'))
cout<<endl;
else
cout<<msg[i];
}
cout<<endl;
return 0;
}

自己写就是了,以:分割,用两个变量记录每次子字符串的开始和结尾,然后for循环赋值给新字符串就是,不是很难啊