tryed to compile this example... don't understand the error

O

Oliver Bleckmann

i tried to compile this example from the web with dev-cpp ide,
but dont understand what's wrong. can u fix it?

#include <iostream>
#include <algorithm>
#include <assert.h>
#include <string>
#include <list>
#include <map>
#include <utility>
#include <sstream>
using namespace std;
list<string> split (string str, char tr)
{
list<string> strElemente; // Ergebnis: Liste von
// Teilstrings
string::iterator pos1, // Anfang/Ende von
pos2; // Teilstrings
pos1 = str.begin(); // Beginn eines Teilstrings
pos2 = find (pos1, str.end(), tr); // Ende eines Teilstrings
while ( pos2 != str.end())
{
// Trenner als Ende gefunden
assert(*pos2==tr);
string elem; // Teilstring
copy (pos1, pos2, back_inserter(elem)); // Teilstring kopieren
strElemente.push_back(elem); // Teilstring speichern
pos1 = pos2;
++pos1; // neuer Anfang hinter altem Ende
pos2 = find (pos1, str.end(), tr); // neue Suche
}
// pos2 zeigt auf das Ende. pos1 zeigt auf den Beginn
// des letzten Teilstrings vor dem Ende.
// Letzten Teilstring extrahieren:
//
string last;
copy (pos1, str.end(), back_inserter(last));
strElemente.push_back(last);
return strElemente;
}
// CGI-Eingabe analysieren.
// erzeugt eine Abbildung Feldname -> Feldwert

map< string, string > analyseCgiParam(string str)
{
list<string> feldListe = split(str, '&'); // in Felder zerlegen
map< string,string > felder; // Ergebnis
// Felder in Paare aus Feldnamen und Wert splitten
//
for ( list<string>::iterator i = feldListe.begin(); i != feldListe.end();
++i)
{
list<string> feldStr = split(*i, '=');
pair< string, string > feld;
feld.first = feldStr.front(); // Feldname
feldStr.pop_front();
feld.second = feldStr.front(); // Feldwert
felder[feld.first] = feld.second; // Paar speichern
}
return felder; // Abbildung Feld-Name -> Feld-Wert zurueck geben
}

int string2Int(string str)
{
istringstream istr (str);
int i;
istr >> i;
return i;
}

int main()
{
// Eingabe analysieren
//
string eingabe;
getline(cin, eingabe);
map< string,string > cgiParam = analyseCgiParam(eingabe);
int z1, z2; // die beiden Zahlen
char op; // die Operation
z1 = string2Int(cgiParam["ZAHL1"]);
z2 = string2Int(cgiParam["ZAHL2"]);
if ( cgiParam["operation"] == "ADD" ) op = '+';
else op = '-';
// HTML-Ausgabe erzeugen
//
cout << "Content-type: text/html" << endl;
cout << endl;
cout << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" << endl;
cout << "<html><head><title>Addier-Verarbeiter</title></head>" << endl;
cout << "<body><h1>Operation ausgef&uuml;hrt</h1>" << endl;
switch (op)
{
case '+':
cout << z1 << " + " << z2 << " = " << z1+z2 << endl;
break;
case '-':
cout << z1 << " + " << z2 << " = " << z1-z2 << endl;
break;
}
cout << "<p>" << endl;
// cout << eingabe << endl;
cout << "<p>" << endl;
cout << "</body></html>" << endl;
}
 
O

Oliver Bleckmann

problem solved!
ironically there is no failure in this source, was fixed by copy and paste,
in
the original code the ' was a ´ sign!!!

Oliver Bleckmann said:
i tried to compile this example from the web with dev-cpp ide,
but dont understand what's wrong. can u fix it?

#include <iostream>
#include <algorithm>
#include <assert.h>
#include <string>
#include <list>
#include <map>
#include <utility>
#include <sstream>
using namespace std;
list<string> split (string str, char tr)
{
list<string> strElemente; // Ergebnis: Liste von
// Teilstrings
string::iterator pos1, // Anfang/Ende von
pos2; // Teilstrings
pos1 = str.begin(); // Beginn eines Teilstrings
pos2 = find (pos1, str.end(), tr); // Ende eines Teilstrings
while ( pos2 != str.end())
{
// Trenner als Ende gefunden
assert(*pos2==tr);
string elem; // Teilstring
copy (pos1, pos2, back_inserter(elem)); // Teilstring kopieren
strElemente.push_back(elem); // Teilstring speichern
pos1 = pos2;
++pos1; // neuer Anfang hinter altem Ende
pos2 = find (pos1, str.end(), tr); // neue Suche
}
// pos2 zeigt auf das Ende. pos1 zeigt auf den Beginn
// des letzten Teilstrings vor dem Ende.
// Letzten Teilstring extrahieren:
//
string last;
copy (pos1, str.end(), back_inserter(last));
strElemente.push_back(last);
return strElemente;
}
// CGI-Eingabe analysieren.
// erzeugt eine Abbildung Feldname -> Feldwert

map< string, string > analyseCgiParam(string str)
{
list<string> feldListe = split(str, '&'); // in Felder zerlegen
map< string,string > felder; // Ergebnis
// Felder in Paare aus Feldnamen und Wert splitten
//
for ( list<string>::iterator i = feldListe.begin(); i != feldListe.end();
++i)
{
list<string> feldStr = split(*i, '=');
pair< string, string > feld;
feld.first = feldStr.front(); // Feldname
feldStr.pop_front();
feld.second = feldStr.front(); // Feldwert
felder[feld.first] = feld.second; // Paar speichern
}
return felder; // Abbildung Feld-Name -> Feld-Wert zurueck geben
}

int string2Int(string str)
{
istringstream istr (str);
int i;
istr >> i;
return i;
}

int main()
{
// Eingabe analysieren
//
string eingabe;
getline(cin, eingabe);
map< string,string > cgiParam = analyseCgiParam(eingabe);
int z1, z2; // die beiden Zahlen
char op; // die Operation
z1 = string2Int(cgiParam["ZAHL1"]);
z2 = string2Int(cgiParam["ZAHL2"]);
if ( cgiParam["operation"] == "ADD" ) op = '+';
else op = '-';
// HTML-Ausgabe erzeugen
//
cout << "Content-type: text/html" << endl;
cout << endl;
cout << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" << endl;
cout << "<html><head><title>Addier-Verarbeiter</title></head>" << endl;
cout << "<body><h1>Operation ausgef&uuml;hrt</h1>" << endl;
switch (op)
{
case '+':
cout << z1 << " + " << z2 << " = " << z1+z2 << endl;
break;
case '-':
cout << z1 << " + " << z2 << " = " << z1-z2 << endl;
break;
}
cout << "<p>" << endl;
// cout << eingabe << endl;
cout << "<p>" << endl;
cout << "</body></html>" << endl;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top