|
源码:
#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 : text/html" << endl << endl;
return;
}
void replaceAll(const string &findstr, const string &replstr)
{
int found = input.find(findstr);
while(found != string::npos)
{
found = input.find(findstr);
}
}
void urldecode()
{
replaceAll("%2C", ",");
replaceAll("+", " ");
split();
}
void split()
{
int count = 0;
char *p;
p = strtok(input.begin(), "&");
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();
return;
}
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>";
return;
}
};
int main()
{
WebProcess web;
web.get();
web.urldecode();
web.split();
web.save();
web.display();
return 0;
}
错误代码:
g++ register.cc
register.cc: In member function `void WebProcess::split()':
register.cc:46: 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*)'
怎么解决啊??? |
|