|
在Redhat8.0下面用G ++编译下面的源代码出现如下错误提示:
1.cpp: In function `void split(const std::string&, char*, std::string*)':
1.cpp:26: 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*)'
在7.2下面编译顺利通过,请问高手在8.0下面的解决方法,谢谢!!
G++版本为3.2.
源代码为:
[code:1]
#include<iostream>
#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" , "<BR>");
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(getenv("QUERY_STRING"));
urldecode(s);
string dest[4];
split(s , "&" ,dest);
cout <<"Content-type: text/html" << endl <<endl;
cout << "<HTML>";
cout << "<H4>" ;
cout << "The name is: " << dest[0] << "<BR>";
cout << "The Address is: " << dest[1] << "<BR>" ;
if(dest[2] == "V1")
cout << "The gender is : Male" << "<BR>";
else
cout << "The gender is : Female" << "<BR>" ;
cout << "</H4>" ;
cout << "</HTML>" ;
return 0;
}
[/code:1] |
|