Trotz FAQ schließen die Programme automatisch
-
Ups, sry. Bin Anfänger.
Hab vor paar Tagen erst mit C++ begonnen. 
Jetzt stehts so im Quellcode, trotzdem schließt das Programm wieder:
#include <iostream> void wait () { std::cin.clear(); std::cin.ignore(std::cin.rdbuf()->in_avail()); std::cin.get(); } int main() { cout<<"Hello World!"<<endl; wait(); return 0; }Wo liegt nun der Fehler? Hoffentlich ist er nicht zu simpel.

-
Wie kommen eigentlich die Leute immer auf die Idee, dass ich (der Benutzer) nochmal extra das Programmende bestaetigen will? Konsolenprogramme rufe ich in der Konsole auf, das heisst, die Ausgabe kann ich auch wunderbar nach Programmende noch betrachten...
-
Bei manchen Implementierungen liefert in_avial() nicht das richtige Ergebnis. Versuch's mal so:
#include <iostream> #include <limits> void wait () { std::cin.clear(); std::cin.ignore(std::numeric_limits<size_t>::max(),'\n'); std::cin.get(); }
-
@ SG1, weil ich ja sehen will obs klappt.

Das ändert leider nichts daran :(:
#include <iostream> #include <limits> void wait () { std::cin.clear(); std::cin.ignore(std::numeric_limits<size_t>::max(),'\n'); std::cin.get(); } int main() { cout<<"Hello World!"<<endl; wait(); return 0; }Und das geht auch nicht:
#include <iostream> #include <conio.h> #include <windows.h> void wait () { FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)); getch(); } int main() { cout<<"Hello World!"<<endl; wait(); return 0; }
-
Hallo
Auch wenn mich alle schlagen:
system("pause"; statt wait()
chrische
-
Hmmm geht auch nicht.
Mittlerweile denke ich, dass es nicht am Quellcode liegt.
Habe eben testweise folgendes in mein Programm reingeschrieben:
float a; cout<<"Zahl eintippen: "; cin>>a;Und nichts passiert. Das Programm startet und schließt, ich kann keine Eingabe tätigen.
-
Hallo
Ich hatte natürlich die schließende Klammer vergessen, aber das sagt dir ja dein compiler.
chrische
-
ich glaube dein compiler kompiliert gar nicht deinen code. gib mal irgend ein mist ein und guck ob dann fehler kommen.
-
Ja, die Klammer war mir schon klar. Ein wenig kenn ich die Syntax ja schon. ^^
Aber frage an die Allgemeinheit, kann es ein Problem mit Borland C++ sein?
-
Sry für den Doppelpost, habs zu spät gesehen.
aijds schrieb:
ich glaube dein compiler kompiliert gar nicht deinen code. gib mal irgend ein mist ein und guck ob dann fehler kommen.
Stimmt, hab wieder irgendwas eingegeben und das Konsolenfenster startet und schließt, ich bekomme keine Fehlermeldung.
-
Hallo
Worauf klickst du? Wann kommt die Konsole?
chrische
-
Ich drücke F9 und kurze Zeit später öffnet sich eine Windows Konsole und schließt sich wieder.
Hier mal die Debug Info:
Thread Start: Thread ID: 3716. Process Project1.exe (2164)
Process Start: C:*PFAD*\Borland Studio Projects\Project1.exe. Base Address: $00400000. Process Project1.exe (2164)
Module Load: Project1.exe. Has Debug Info. Base Address: $00400000. Process Project1.exe (2164)
Module Load: ntdll.dll. No Debug Info. Base Address: $7C910000. Process Project1.exe (2164)
Module Load: KERNEL32.dll. No Debug Info. Base Address: $7C800000. Process Project1.exe (2164)
Module Load: rtl100.bpl. No Debug Info. Base Address: $51F00000. Process Project1.exe (2164)
Module Load: OLEAUT32.dll. No Debug Info. Base Address: $770F0000. Process Project1.exe (2164)
Module Load: msvcrt.dll. No Debug Info. Base Address: $77BE0000. Process Project1.exe (2164)
Module Load: USER32.dll. No Debug Info. Base Address: $7E360000. Process Project1.exe (2164)
Module Load: GDI32.dll. No Debug Info. Base Address: $77EF0000. Process Project1.exe (2164)
Module Load: ADVAPI32.dll. No Debug Info. Base Address: $77DA0000. Process Project1.exe (2164)
Module Load: RPCRT4.dll. No Debug Info. Base Address: $77E50000. Process Project1.exe (2164)
Module Load: ole32.dll. No Debug Info. Base Address: $774B0000. Process Project1.exe (2164)
Module Load: VERSION.dll. No Debug Info. Base Address: $77BD0000. Process Project1.exe (2164)
Module Load: MPR.dll. No Debug Info. Base Address: $71A80000. Process Project1.exe (2164)
Module Load: IMAGEHLP.dll. No Debug Info. Base Address: $76C50000. Process Project1.exe (2164)
Module Load: WSOCK32.dll. No Debug Info. Base Address: $71A30000. Process Project1.exe (2164)
Module Load: WS2_32.dll. No Debug Info. Base Address: $71A10000. Process Project1.exe (2164)
Module Load: WS2HELP.dll. No Debug Info. Base Address: $71A00000. Process Project1.exe (2164)
Module Load: OLEACC.dll. No Debug Info. Base Address: $74C00000. Process Project1.exe (2164)
Module Load: MSVCP60.dll. No Debug Info. Base Address: $76020000. Process Project1.exe (2164)
Module Load: borlndmm.dll. No Debug Info. Base Address: $21660000. Process Project1.exe (2164)
Module Load: cc3270mt.dll. No Debug Info. Base Address: $32700000. Process Project1.exe (2164)
Module Load: UxTheme.dll. No Debug Info. Base Address: $5B0F0000. Process Project1.exe (2164)
-
leg doch mal ein neues projekt an.
-
Hab jetzt folgendes gemacht:
- Borland neugestartet
- neues Projekt angelegt
- "Console Application"
- daraufhin öffnet sich unit.cpp & Projekt1
- in Projekt1 hab ich einfach nur "asdadasd" reingeschrieben
- F9 gedrückt
- dann kompiliert und linkt Borland ~25000 Zeilen (so wirds mir zumindest in dem Fenster angezeigt)
- Errors: 0
- Die Konsole öffnet sich und schließt sich.Da muss doch irgendwo ein Einstellungsfehler sein oder?
-
Hallo
Kleiner Tip : Dein Quellcode gehört in die Unit.cpp, nicht in die Project1.bpf .
Und dort drin findest du nämlich auch schon eine main-Funktion (kann auch WinMain sein, ist aber auch gut). Diese brauchst du nur zu erweitern. Du darfst aber auch nicht die WinMain-Deklaration durch main ersetzen.bis bald
akari
-
Das war der Fehler. Da hatte ich aber auch ein Brett vorm Kopf.
Danke an alle.
