C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Oliver Bleckmann
Guest





PostPosted: Sat Nov 18, 2006 10:10 am    Post subject: tryed to compile this example... don't understand the error Reply with quote



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;
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.