|
代码如下:
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
void replaceAll(string &src,const string &findstr,const string &replstr)
{
int found = src.find(findstr);
while(found != string::npos)
{
src.replace(found,findstr.length(),replstr);
found = src.find(findstr);
}
}
void urldecode(string &s)
{
replaceAll(s,"%2C",",");
replaceAll(s,"%0D%0A","\n");
replaceAll(s,"+"," ");
}
void split(const string &s,char *delim,string dest[])
{
string temp = s;
int count = 0;
char *p;
p = strtok(temp.begin(),delim);
while(p!=NULL)
{
dest[count] = p;
count++;
p = strtok(0,delim);
}
for(int temp=0;temp != count;temp++)
dest[temp].erase(0,dest[temp].find("=")+1);
}
int main()
{
string s;
count << "Enter encode string : ";
cin >> s;
cin.ignore();
urldecode(s);
string dest[2];
split(s,"&",dest);
cout << "N1 has the value: " << dest[0] << endl;
cout << "N2 has the value: " << dest[1] << endl;
return 0;
}
在GCC下编译,错误信息如下:
[langjian@localhost NIIT]$ g++ -o 10D2 10D2.cc
10D2.cc: In function `void split(const std::string&, char*, std::string*)':
10D2.cc:30: cannot convert `__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> > >' to
`char*' for argument `1' to `char* strtok(char*, const char*)'
10D2.cc: In function `int main()':
10D2.cc:44: invalid operands of types `<unknown type>' and `const char[23]' to
binary `operator<<'
但是这代码在VC++ 6.0中去顺利通过!
还望各位高手多多指教!
谢谢! |
|