plzz see my codes and tell me what's wrong?
I want to make c++ for Cgi
#include <fstream>
#include <string>
#include <cstdio>
struct Applicant
{
string name, address, city, phone, mail;
};
class WebProcess
{
string input, dest[5];
Applicant app;
public:
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(),"&");
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];
}
save()
{
ofstream file;
file.open("applicant.dat",ios:ut|ios::app);
file.write((char *)&app,sizeof(app));
file.close();
}
display()
{
cout << "<html>";
cout << "Name:"<< app.name << "<br>";
cout << "Address:"<< app.address << "<br>";
cout << "City:"<< app.city << "<br>";
cout << "Phone:"<< app.phone << "<br>";
cout << "Mail:"<< app.mail << "<br><br><br><br><br><br>";
cout << "have been recorded.";
cout << "thk";
cout << "</html>";
}
};
int main()
{
WebProcess web;
web.get();
web.urldecode();
web.split();
web.save();
web.display();
return 0;
}
when I compile :::
nui-ibook-g4:~ surasakthepa-armonkit$ g++ ./c++/webadd.cc./c++/webadd.cc:7: error: 'string' does not name a type
./c++/webadd.cc:11: error: 'string' does not name a type
./c++/webadd.cc:15: error: ISO C++ forbids declaration of 'get' with no type
./c++/webadd.cc:21: error: expected %<,%> or %<...%> before '&' token
./c++/webadd.cc:21: error: ISO C++ forbids declaration of 'string' with no type
./c++/webadd.cc:59: error: ISO C++ forbids declaration of 'save' with no type
./c++/webadd.cc:67: error: ISO C++ forbids declaration of 'display' with no type
./c++/webadd.cc: In member function `int WebProcess::get()':
./c++/webadd.cc:17: error: 'input' was not declared in this scope
./c++/webadd.cc:18: error: 'cout' was not declared in this scope
./c++/webadd.cc:18: error: 'endl' was not declared in this scope
./c++/webadd.cc: In member function `void WebProcess::replaceAll(int)':
./c++/webadd.cc:23: error: 'input' was not declared in this scope
./c++/webadd.cc:23: error: 'findstr' was not declared in this scope
./c++/webadd.cc:24: error: 'string' is not a class or namespace
./c++/webadd.cc:24: error: 'npos' was not declared in this scope
./c++/webadd.cc:26: error: 'replstr' was not declared in this scope
./c++/webadd.cc: In member function `void WebProcess::urldecode()':
./c++/webadd.cc:33: error: no matching function for call to 'WebProcess::replaceAll(const char [4], const char [2])'
./c++/webadd.cc:21: note: candidates are: void WebProcess::replaceAll(int)
./c++/webadd.cc:34: error: no matching function for call to 'WebProcess::replaceAll(const char [2], const char [2])'
./c++/webadd.cc:21: note: candidates are: void WebProcess::replaceAll(int)
./c++/webadd.cc: In member function `void WebProcess::split()':
./c++/webadd.cc:42: error: 'input' was not declared in this scope
./c++/webadd.cc:45: error: 'dest' was not declared in this scope
./c++/webadd.cc:47: error: expected `)' before ';' token
./c++/webadd.cc:51: error: 'dest' was not declared in this scope
./c++/webadd.cc:52: error: 'struct Applicant' has no member named 'name'
./c++/webadd.cc:52: error: 'dest' was not declared in this scope
./c++/webadd.cc:53: error: 'struct Applicant' has no member named 'address'
./c++/webadd.cc:54: error: 'struct Applicant' has no member named 'city'
./c++/webadd.cc:55: error: 'struct Applicant' has no member named 'phone'
./c++/webadd.cc:56: error: 'struct Applicant' has no member named 'mail'
./c++/webadd.cc: In member function `int WebProcess::save()':
./c++/webadd.cc:61: error: 'ofstream' was not declared in this scope
./c++/webadd.cc:61: error: expected `;' before "file"
./c++/webadd.cc:62: error: 'file' was not declared in this scope
./c++/webadd.cc:62: error: `ios' has not been declared
./c++/webadd.cc:62: error: 'out' was not declared in this scope
./c++/webadd.cc:62: error: `ios' has not been declared
./c++/webadd.cc: In member function `int WebProcess::display()':
./c++/webadd.cc:69: error: 'cout' was not declared in this scope
./c++/webadd.cc:70: error: 'struct Applicant' has no member named 'name'
./c++/webadd.cc:71: error: 'struct Applicant' has no member named 'address'
./c++/webadd.cc:72: error: 'struct Applicant' has no member named 'city'
./c++/webadd.cc:73: error: 'struct Applicant' has no member named 'phone'
./c++/webadd.cc:74: error: 'struct Applicant' has no member named 'mail'
nui-ibook-g4:~ surasakthepa-armonkit$
thk before
I want to make c++ for Cgi
#include <fstream>
#include <string>
#include <cstdio>
struct Applicant
{
string name, address, city, phone, mail;
};
class WebProcess
{
string input, dest[5];
Applicant app;
public:
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(),"&");
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];
}
save()
{
ofstream file;
file.open("applicant.dat",ios:ut|ios::app);
file.write((char *)&app,sizeof(app));
file.close();
}
display()
{
cout << "<html>";
cout << "Name:"<< app.name << "<br>";
cout << "Address:"<< app.address << "<br>";
cout << "City:"<< app.city << "<br>";
cout << "Phone:"<< app.phone << "<br>";
cout << "Mail:"<< app.mail << "<br><br><br><br><br><br>";
cout << "have been recorded.";
cout << "thk";
cout << "</html>";
}
};
int main()
{
WebProcess web;
web.get();
web.urldecode();
web.split();
web.save();
web.display();
return 0;
}
when I compile :::
nui-ibook-g4:~ surasakthepa-armonkit$ g++ ./c++/webadd.cc./c++/webadd.cc:7: error: 'string' does not name a type
./c++/webadd.cc:11: error: 'string' does not name a type
./c++/webadd.cc:15: error: ISO C++ forbids declaration of 'get' with no type
./c++/webadd.cc:21: error: expected %<,%> or %<...%> before '&' token
./c++/webadd.cc:21: error: ISO C++ forbids declaration of 'string' with no type
./c++/webadd.cc:59: error: ISO C++ forbids declaration of 'save' with no type
./c++/webadd.cc:67: error: ISO C++ forbids declaration of 'display' with no type
./c++/webadd.cc: In member function `int WebProcess::get()':
./c++/webadd.cc:17: error: 'input' was not declared in this scope
./c++/webadd.cc:18: error: 'cout' was not declared in this scope
./c++/webadd.cc:18: error: 'endl' was not declared in this scope
./c++/webadd.cc: In member function `void WebProcess::replaceAll(int)':
./c++/webadd.cc:23: error: 'input' was not declared in this scope
./c++/webadd.cc:23: error: 'findstr' was not declared in this scope
./c++/webadd.cc:24: error: 'string' is not a class or namespace
./c++/webadd.cc:24: error: 'npos' was not declared in this scope
./c++/webadd.cc:26: error: 'replstr' was not declared in this scope
./c++/webadd.cc: In member function `void WebProcess::urldecode()':
./c++/webadd.cc:33: error: no matching function for call to 'WebProcess::replaceAll(const char [4], const char [2])'
./c++/webadd.cc:21: note: candidates are: void WebProcess::replaceAll(int)
./c++/webadd.cc:34: error: no matching function for call to 'WebProcess::replaceAll(const char [2], const char [2])'
./c++/webadd.cc:21: note: candidates are: void WebProcess::replaceAll(int)
./c++/webadd.cc: In member function `void WebProcess::split()':
./c++/webadd.cc:42: error: 'input' was not declared in this scope
./c++/webadd.cc:45: error: 'dest' was not declared in this scope
./c++/webadd.cc:47: error: expected `)' before ';' token
./c++/webadd.cc:51: error: 'dest' was not declared in this scope
./c++/webadd.cc:52: error: 'struct Applicant' has no member named 'name'
./c++/webadd.cc:52: error: 'dest' was not declared in this scope
./c++/webadd.cc:53: error: 'struct Applicant' has no member named 'address'
./c++/webadd.cc:54: error: 'struct Applicant' has no member named 'city'
./c++/webadd.cc:55: error: 'struct Applicant' has no member named 'phone'
./c++/webadd.cc:56: error: 'struct Applicant' has no member named 'mail'
./c++/webadd.cc: In member function `int WebProcess::save()':
./c++/webadd.cc:61: error: 'ofstream' was not declared in this scope
./c++/webadd.cc:61: error: expected `;' before "file"
./c++/webadd.cc:62: error: 'file' was not declared in this scope
./c++/webadd.cc:62: error: `ios' has not been declared
./c++/webadd.cc:62: error: 'out' was not declared in this scope
./c++/webadd.cc:62: error: `ios' has not been declared
./c++/webadd.cc: In member function `int WebProcess::display()':
./c++/webadd.cc:69: error: 'cout' was not declared in this scope
./c++/webadd.cc:70: error: 'struct Applicant' has no member named 'name'
./c++/webadd.cc:71: error: 'struct Applicant' has no member named 'address'
./c++/webadd.cc:72: error: 'struct Applicant' has no member named 'city'
./c++/webadd.cc:73: error: 'struct Applicant' has no member named 'phone'
./c++/webadd.cc:74: error: 'struct Applicant' has no member named 'mail'
nui-ibook-g4:~ surasakthepa-armonkit$
thk before