Forum
Tipps
News
Menu-Icon

[C++] HTML Code Generieren

Hi,

ich habe ein programm geschrieben das einen HTML Code Generiert mit bestimmten angaben (Variablen).

Es gibt einmal im Ornder "projekt" die Files mit den Informationen(AUTO01.dat AUTO02.dat ... AUTO20.dat).
Jedes dieser Files hat einen Eintrag/Artikel gespeichert !

Beispiel Inhalt einer AUTOxx.dat:

testtest
grafik.png
12.000
yes
TESTTEXT<br/>TESTTEXT

Jede zeile hat später eine bedeutung in der HTML Datei.

Alsoo tut er vollgändes:

-Den beginnenden HTML-Code Generieren (<html><head> etc.)
-Erste datei "AUTO01.dat" laden
-jede zeile lesen und in eine Variable speichern
-HTML-Code generieren mit dem Inhalt der Variablen
-Link generieren + die Gelinkte seite wird generiert !
-Zweite datei "AUTO02.dat" laden
usw. bis zur 20. Datei "AUTO20.dat"

So und nun klappt das nicht 100%tig...

mein bisheriger quellcode:

HTML-GEN.cpp
#include <iostream>
#include <conio.h>
#include <fstream.h>
#include <strings.h>

#include "console_style.h"
#include "HTML-GEN.h"



using namespace std;


int main()
{
    string NAME;
    string IMG;
    string PRISE;
    string HIGHLIGHT;
    string DESC;
    string CMD;
    BEGIN:
    cout << "Welcome in MICRO-CMS 1.0\n";
    cout << "By Tomasz Kruszewski.\n";
    cout << "Kommando: ";
    cin >> CMD;
    if(CMD == "f" || CMD == "F")
    {
       COMPILE();
       cout << "Die Seite wurde fertiggestellt!";
    }
    else if(CMD == "a" || CMD == "A")
    {
       string AUTONO;
       cout << "Name: ";
       cin >> NAME;
       cout << "Bild: ";
       cin >> IMG;
       cout << "Preis: ";
       cin >> PRISE;
       cout << "Highlight: ";
       cin >> HIGHLIGHT;
       cout << "Beschreibung: ";
       cin >> DESC;
       cout << "AUTONUMMER: ";
       cin >> AUTONO;
       AddArtical(NAME, IMG, PRISE, HIGHLIGHT, DESC, AUTONO);
    }   
    goto BEGIN;
    getch();
    return 0;
}   

HTML-GEN.h
void COMPILE()
{
    ofstream begin_code("cars.html");
    begin_code << "<html><head></head><body background=\"body.bmp\">";
    begin_code.close();
   
    string pfad = "projekt\\AUTO";
    string nummer = "01";
    string dat = ".dat";
   
    string dpfad = "DETP";
    string dnummer = "01";
    string [url=http://www.computerhilfen.de/fachbegriffe-h-HTML.html][b]html [/b][/url] = ".html";
   
    string link = "PGAUT";
   
    string s;

    int i;
    int line;
   
    string name;
    string img;
    string prise;
    string high;
    string desc;
   
    while(i <= 20)
    {
        dpfad = "DETP";
        pfad = "projekt\\AUTO";
        link = "PGAUT";
        if(i == 0){pfad = pfad + "01" + dat; dpfad = dpfad + "01" + html; link = link + "01" + html;}
        if(i == 1){pfad = pfad + "02" + dat; dpfad = dpfad + "02" + html; link = link + "02" + html;}
        if(i == 2){pfad = pfad + "03" + dat; dpfad = dpfad + "03" + html; link = link + "03" + html;}
        if(i == 3){pfad = pfad + "04" + dat; dpfad = dpfad + "04" + html; link = link + "04" + html;}
        if(i == 4){pfad = pfad + "05" + dat; dpfad = dpfad + "05" + html; link = link + "05" + html;}
        if(i == 5){pfad = pfad + "06" + dat; dpfad = dpfad + "06" + html; link = link + "06" + html;}
        if(i == 6){pfad = pfad + "07" + dat; dpfad = dpfad + "07" + html; link = link + "07" + html;}
        if(i == 7){pfad = pfad + "08" + dat; dpfad = dpfad + "08" + html; link = link + "08" + html;}
        if(i == 8){pfad = pfad + "09" + dat; dpfad = dpfad + "09" + html; link = link + "09" + html;}
        if(i == 9){pfad = pfad + "10" + dat; dpfad = dpfad + "10" + html; link = link + "10" + html;}
        if(i == 10){pfad = pfad + "11" + dat; dpfad = dpfad + "11" + html; link = link + "11" + html;}
        if(i == 11){pfad = pfad + "12" + dat; dpfad = dpfad + "12" + html; link = link + "12" + html;}
        if(i == 12){pfad = pfad + "13" + dat; dpfad = dpfad + "13" + html; link = link + "13" + html;}
        if(i == 13){pfad = pfad + "14" + dat; dpfad = dpfad + "14" + html; link = link + "14" + html;}
        if(i == 14){pfad = pfad + "15" + dat; dpfad = dpfad + "15" + html; link = link + "15" + html;}
        if(i == 15){pfad = pfad + "16" + dat; dpfad = dpfad + "16" + html; link = link + "16" + html;}
        if(i == 16){pfad = pfad + "17" + dat; dpfad = dpfad + "17" + html; link = link + "17" + html;}
        if(i == 17){pfad = pfad + "18" + dat; dpfad = dpfad + "18" + html; link = link + "18" + html;}
        if(i == 18){pfad = pfad + "19" + dat; dpfad = dpfad + "19" + html; link = link + "19" + html;}
        if(i == 19){pfad = pfad + "20" + dat; dpfad = dpfad + "20" + html; link = link + "20" + html;}
       
        ifstream autos(pfad.c_str(), ios::app);
        line=0;
        while(getline(autos,s))
        {
            line++;
            if(line==1)
            {
                name=s;           
            }
            else if(line==2)
            {
                img=s;
            }
            else if(line==3)
            {
                prise=s;
            }
            else if(line==4)
            {
                high=s;
            }
            else if(line==5)
            {
                desc=s;
            }
        }
        autos.close();
        ofstream compile("cars.html", ios::app);
        compile << "<font face=\"Bitstream Vera Sans Mono\" size=\"+1\">";
        if(high == "yes")
        {
            compile << "<strong><font color=\"#FF0000\">" << name << "</font></strong>";
        }
        if(high == "no")
        {
            compile << name;
        }
        compile << "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        compile << prise;
        compile << "<br/><img src=\"" << img << "\" hight=\"100\" weight=\"100\" />";
        compile << desc;
        compile << "<br/><a href=\"" << link << "\">Details...</a>";
        compile << "<br/>";
        compile.close();
       
        ofstream link(dpfad.c_str());
        link << "<html><head></head><body background=\"body.bmp\"><font face=\"Bitstream Vera Sans Mono\">";
        link << "<h1>" << name << "</h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<h1><u>" << prise << "</u></h1>";
        link << "<br/><img src=\"" << img << "\" /><br/>";
        link << desc << "<br/></body></html>";
        link.close();
        i++;
    }   
}
     
void AddArtical(string name, string img, string prise, string highlight, string description, string autonumber)
{
    string path = "projekt\\AUTO";
    string dat = ".dat";
    path = path + autonumber + dat;
    ofstream AUTODAT(path.c_str());
    AUTODAT << name << "\n";
    AUTODAT << img << "\n";
    AUTODAT << prise << "\n";
    AUTODAT << highlight << "\n";
    AUTODAT << description << "\n";
    AUTODAT.close();
}

Programm Ablauf in main():

Es wird um ein Kommando gebeten. Wenn man f drückt wird das gesamte so zu sagen "Kompiliert" bzw. wird der HTML-CODE Generiert ! Wenn man a drückt kann man ein "Artikel" hinzufügen (sprich AUTOxx.dat)

Es lässt sich schon kompilieren nur der Inhalt der Dabei rauskommt ist unvollständig !!
Vollgändes Problem tritt auf:
Überall wo die Variablen "name, prise, desc" sind werden sie nicht eingelesen.. wieso.. ?

Ich hoffe das jemand sich die zeit nimmt mir zu helfen...

DANKE im Vorraus

MFG
TOMEK 
« Letzte Änderung: 28.03.07, 09:43:39 von Sniper-Hawk »

Antworten zu [C++] HTML Code Generieren:

Ahja der generierte HTML-Quellcode:

<html><head></head><body background="body.bmp">
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT01.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT02.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT03.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT04.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT05.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT06.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT07.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT08.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT09.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT10.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT11.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT12.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT13.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT14.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT15.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT16.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT17.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT18.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT19.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT20.html">Details...</a><br/>
<font face="Bitstream Vera Sans Mono" size="+1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><img src="" hight="100" weight="100" /><br/><a href="PGAUT">Details...</a><br/>

sorry der ist unformatiert Generiert worden ! Aber schon so sieht man das einpar teile die "eigentlich" gespeichert werden sollten nicht da sind !

MFG
TOMEK 
« Letzte Änderung: 27.03.07, 22:00:29 von Sniper-Hawk »

hab das problem gelöst.. beim ifstream autos(pfad.c_str()) hab ich ausversehen ein ios::app hinzugefügt, was beim input filestream eher nicht funktionieren würde.. ok.. ;D

MFG
TOMEK   

« Letzte Änderung: 02.04.07, 20:27:55 von Sniper-Hawk »

« "Hello World" --->C++Dart-script(?) »
 

Fremdwörter? Erklärungen im Lexikon!
HTML
HTML steht für Hyper Text Markup Language, ist die Sprache, mit der Internetseiten kodiert werden. Es handelt sich dabei um ASCII Text, in den die HTML Befehle einge...

XHTML
Die Extensible Hypertext Markup Language, kurz XHTML, ist eine textbasierte Auszeichnungssprache zur semantischen Auszeichnung von Bildern, Texten und Hyperlinks in Dokum...

Quellcode
Ein Quellcode, auch als Quelltext bekannt, bezeichnet den unkompilierten Programm-Code einer Software. Quell- oder Programm-Code ist der auch für Menschen lesbare Co...


@ Zeichen: Notfall-Trick per ASCII Code!