|
#include <cstdlib>
#include <fstream>
#include <string>
#include <cstdio>
#include <iostream>
using namespace std;
struct Applicant
{
string name, address, city, phone, mail;
};
class WebProcess
{
private:
string input, dest[5];
Applicant app;
public:
void get()
{
input.assign(getenv("QUERY_STRING"));
cout << "Content-type :html/text" << endl << endl;
}
void replaceAll(const string &findstr, const string &replstr)
{
int found = input.find(findstr);
while(found != string::npos)
{
input.replace(found, findstr.length(), replstr);
found = input.find(findstr);
}
}
void urldecode()
{
replaceAll("%2C", ",");
replaceAll("+", " ");
split();
}
void split()
{
int count = 0;
char *p;
p = strtok(input.begin(), "&"); //这是第47行
while(p != NULL)
{
dest[count] = p;
count++;
p = strtok(0, "&");
}
for(int counter = 0; counter != count; counter++)
dest[counter].erase(0,dest[counter].find("=") + 1);
app.name = dest[0];
app.address = dest[1];
app.city = dest[2];
app.phone = dest[3];
app.mail = dest[4];
}
void save()
{
ofstream file;
file.open("applicant.dat",ios:ut|ios::app);
file.write((char *)&app,sizeof(app));
file.close();
}
void display()
{
cout << "<html>";
cout << "<h1>";
cout << "The details saved are:" << "<br>";
cout << "</h1>";
cout << "Name: " << app.name << "<br>";
cout << "Address: " << app.address << "<br>";
cout << "City: " << app.city << "<br>";
cout << "Phone: " << app.phone << "<br>";
cout << "E-Mail id: " << app.mail << "<br><br><br><br>";
cout << "<h2>Your details have been recorded.";
cout << "Thanks!!!!</h2>";
cout << "</html>";
}
};
int main()
{
WebProcess web;
web.get();
web.urldecode();
web.split();
web.save();
web.display();
return 0;
}
以上是源码,编译时以下错误,怎么解决啊????
g++ 13d2.cc
13d2.cc: In member function `void WebProcess::split()':
13d2.cc:47: 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*)' |
|