2014年11月29日 星期六

c++ 自建 split 函式

#include <iostream>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

void split(string str,string word[])
{
istringstream iss(str);

int i=0;
while(iss >> word[i])
 i++;
}

int main()
{
string str = "220.70.76.1";
replace( str.begin(), str.end(), '.', ' ');
string word[30];
split(str,word);
int i=0;
while(word[i]!="")
{
cout << word[i] << '\n';
i++;
}
}