Fehler mit Microsoft Datei (Anschein)
-
Was die Methode bezwecken soll:
1. Sie soll die längste Länge der Strings aus dem Vector item_labels herauslesen.
2. a
Sie soll dann deb String +" "+ item_value mal ein Zeichen ausgeben, wenn der String's Länge die längste Länge entspricht.
2. b
Andernfalls soll sie erstmal so viele leerzeichen einfügen, bis der String die Länge von der längsten Länge hat.
Und danach dasselbe machen wie oben beschrieben (siehe 2.a)Vorraussetzungen:
Stellt euch vor das c println u.s.w. sind was wie cout << ok?void Diagram::printDiagram(Console c) { c.println(title+" :"); int length = 0; // Look for bigest Item Label Length for(int i = 0;i<items;i++) { if(item_labels[i].length()>length) { length = item_labels[i].length(); } } for(int i = 0;i<items;i++) { c.print(item_labels[i]); // Asks for enough Space, so that all diagrams are at the same start if(item_labels[i].length()==length) { } else if(item_labels[i].length()<=length) { while(item_labels[i].length()<length) { c.print(" "); item_labels[i] += " "; } } c.print(": "); for(int j = 0;j<item_values[i];j++) { c.print(diagramChar); } c.nextLine(); } c.paragraph(); }Ich bekomme das hier als Fehler:
onsole Library.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file The program '[9268] Console Library.exe: Native' has exited with code 3 (0x3).Und noch mal ein passendes Fenster :
www.imperatorclan.kilu.de/myUploads/Error Message.PNGUnd wenn man auf continue klickt, kommt genau dasselbe fenster noch mal, und im code editor öffnet sich sogar der code von der datei, die ich nicht programmiert habe:
/*** *dbgnew.cpp - defines C++ scalar delete routine, debug version * * Copyright (c) Microsoft Corporation. All rights reserved. * *Purpose: * Defines C++ scalar delete() routine. * *******************************************************************************/ #ifdef _DEBUG #include <cruntime.h> #include <malloc.h> #include <mtdll.h> #include <dbgint.h> #include <rtcsup.h> /*** *void operator delete() - delete a block in the debug heap * *Purpose: * Deletes any type of block. * *Entry: * void *pUserData - pointer to a (user portion) of memory block in the * debug heap * *Return: * <void> * *******************************************************************************/ void operator delete( void *pUserData ) { _CrtMemBlockHeader * pHead; RTCCALLBACK(_RTC_Free_hook, (pUserData, 0)); if (pUserData == NULL) return; _mlock(_HEAP_LOCK); /* block other threads */ __TRY /* get a pointer to memory block header */ pHead = pHdr(pUserData); /* verify block type */ _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)); _free_dbg( pUserData, pHead->nBlockUse ); __FINALLY _munlock(_HEAP_LOCK); /* release other threads */ __END_TRY_FINALLY return; } #endif /* _DEBUG */Und Breakpoint ist auf zeile 52 gesetzt.
Ich glaube damit habe ich nichts zu tun oder?
die methoden c.paragraph und c.nextLine, habe ich auch weggelassen, und da kam trotzdem der Fehler. Kann mir einer helfen?
Developer_X 
-
Der Code sieht erstmal in Ordnung aus, angenommen, dass es mit Console, item_labels & Co. jeweils seine Richtigkeit hat. Ist Console eine kopierbare Klasse? Kann ich mir irgendwie nicht vorstellen...
Übrigens möchte ich dir den vorletzten Stringkonstruktor auf dieser Seite vorstellen:
http://www.cplusplus.com/reference/string/string/string/Damit reduzierst du den Codeausschnitt leicht auf die Hälfte der Zeilen.
-
Da ich mal davon ausgehe, dass MS keine schwerwiegenden Fehler in ihrer Stanardbibliothek eingebaut hat, wird das schon an deinem Programm liegen. Guck mal weiter oben im Callstack, welche Zeile aus deinem Programm letztendlich den operator delete aufgerufen hat. Dann kannst du uns den Übeltäter nennen und wir können weiter gucken.
Der Fehler mit den fehlenden PDB-Dateien hat erstmal nichts direkt mit deinem Programm zu tun. Der Debugger sucht Debugsymbole zu einigen Bibliotheken und findet sie nicht. Er sollte trotzdem in der Lage sein zu sagen, an welcher Stelle in deinem Programmcode es hackt.
-
Es handelt sich um einen konflikt zwischen Debug und Release new/delete funktionen.
suchmal ob du irgendwo bei dir was findest aller:
#define new ...
früher stand das mal oben in den headern.
Benutzt du Biblotheken die evtl als Debugversion kompeliert wurden (Sofern dein Programm nicht debugversion ist kommt es je nach verlinkung zu Problemen)
Auch kann das Problem auf eine Speicherbeschädigung hindeuten. (du machst was nicht richtig). Die fehlenden PDB Dateien sind jedenfalls nicht die problemursache.
-
Ok, danke erstmal für die Tipps, also, erstmal habe ich hier codes euch mal gegeben. Vielleicht seht ihrs schon, die Headerdateien hab ich nicht angezeigt, weil die wirklich laufen.
1. Der Code läuft ohne Probleme
2. Erst wenn das Programm fertig ist, gibts den Fehler.3.Gesamte Ausgabe des "Output"
'Console Library.exe': Loaded 'F:\C++ Projekte\Console Library\Debug\Console Library.exe', Symbols loaded. 'Console Library.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded. 'Console Library.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded. 'Console Library.exe': Loaded 'C:\Program Files\Common Files\LogiShrd\LVMVFM\LVPrcInj.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\user32.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\gdi32.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\advapi32.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\rpcrt4.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\imm32.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\msctf.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\msvcrt.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\lpk.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\usp10.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Program Files\Google\Google Desktop Search\GoogleDesktopNetwork3.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\ws2_32.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\nsi.dll', Cannot find or open the PDB file The thread 'Win32 Thread' (0x2ecc) has exited with code 262144 (0x40000). 'Console Library.exe': Unloaded 'C:\Program Files\Google\Google Desktop Search\GoogleDesktopNetwork3.dll' 'Console Library.exe': Unloaded 'C:\Windows\System32\ws2_32.dll' 'Console Library.exe': Unloaded 'C:\Windows\System32\nsi.dll' The thread 'Win32 Thread' (0x21cc) has exited with code 0 (0x0). 'Console Library.exe': Loaded 'C:\Windows\System32\uxtheme.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\ole32.dll', Cannot find or open the PDB file 'Console Library.exe': Loaded 'C:\Windows\System32\oleaut32.dll', Cannot find or open the PDB file The program '[12212] Console Library.exe: Native' has exited with code 3 (0x3).4. Code von Diagram
#include "StdAfx.h" #include <stdio.h> #include <string> #include <vector> #include "Console.h" #include "Diagram.h" /* * Author Kevin Riehl */ // Attributes string title; char diagramChar = '|'; int items = 0; vector<string> item_labels; vector<int> item_values; // Constructor and Destructor Diagram::~Diagram(void) { delete &item_labels; delete &item_values; delete &diagramChar; delete &title; delete &items; } Diagram::Diagram() { } // Methods void Diagram::addItem(string item, int value) { item_labels.push_back(item); item_values.push_back(value); items++; } void Diagram::printDiagram(Console c) { c.println(title+" :"); int length = 0; // Look for bigest Item Label Length for(int i = 0;i<items;i++) { if(item_labels[i].length()>length) { length = item_labels[i].length(); } } for(int i = 0;i<items;i++) { c.print(item_labels[i]); // Asks for enough Space, so that all diagrams are at the same start if(item_labels[i].length()==length) { } else if(item_labels[i].length()<=length) { while(item_labels[i].length()<length) { c.print(" "); item_labels[i] += " "; } } string chars (item_values[i],diagramChar); c.print(": "+chars); c.nextLine(); } c.paragraph(); } // Setters void Diagram::setDiagramChar(char c) { diagramChar = c; } void Diagram::setTitle(string s) { title = s; } // Getters string Diagram::getTitle() { return title; } char Diagram::getDiagramChar() { return diagramChar; } vector<string> Diagram::getItems() { return item_labels; }(Die Headerdateien zeige ich jetzt mal nicht an, weil die gehen wirklich)
5. Console
#include "StdAfx.h" #include <stdio.h> #include <iostream> #include <string> #include <time.h> #include <windows.h> #include "Diagram.h" #include "Console.h" /* *Author Kevin Riehl */ // Attributes int waitTime; // Constructor Console::Console() { waitTime = 100; } // Methods // Setters & Getters void Console::setWaitTime(int msecs) { waitTime = msecs; } int Console::getWaitTime() { return waitTime; } // Waiting Methods void Console::wait ( int seconds ) { Sleep(seconds*1000); } void Console::wait_sec ( int seconds ) { Sleep(seconds*1000); } void Console::wait_msec ( int seconds ) { Sleep(seconds); } // Line-Jump Methods void Console::nextLine() { cout << "\n"; } void Console::paragraph() { nextLine(); nextLine(); } // Basic Printing Methods // Variations of Basic Method, which tokes the text, and print every char // String void Console::print(string text) { char* s = const_cast<char*>(text.c_str()); for(int i = 0;i<text.length();i++) { cout << s[i]; wait_msec(waitTime); } } void Console::println(string text) { char* s = const_cast<char*>(text.c_str()); for(int i = 0;i<text.length();i++) { cout << s[i]; wait_msec(waitTime); } nextLine(); } void Console::print(string text,int sec) { char* s = const_cast<char*>(text.c_str()); for(int i = 0;i<text.length();i++) { cout << s[i]; wait_sec(sec); } } void Console::println(string text,int sec) { char* s = const_cast<char*>(text.c_str()); for(int i = 0;i<text.length();i++) { cout << s[i]; wait_sec(sec); } nextLine(); } // Char void Console::print(char c) { cout << c; wait_msec(waitTime); } void Console::println(char c) { cout << c; wait_msec(waitTime); nextLine(); } void Console::print(char c,int sec) { cout << c; wait_sec(sec); } void Console::println(char c,int sec) { cout << c; wait_sec(sec); nextLine(); } // Double void Console::print(double d) { cout << d; wait_msec(waitTime); } void Console::println(double d) { cout << d; wait_msec(waitTime); nextLine(); } void Console::print(double d,int sec) { cout << d; wait_sec(sec); } void Console::println(double d,int sec) { cout << d; wait_sec(sec); nextLine(); } // Float void Console::print(float f) { cout << f; wait_msec(waitTime); } void Console::println(float f) { cout << f; wait_msec(waitTime); nextLine(); } void Console::print(float f,int sec) { cout << f; wait_sec(sec); } void Console::println(float f,int sec) { cout << f; wait_sec(sec); nextLine(); } // Int void Console::print(int n) { cout << n; wait_msec(waitTime); } void Console::println(int n) { cout << n; wait_msec(waitTime); nextLine(); } void Console::print(int n,int sec) { cout << n; wait_sec(sec); } void Console::println(int n,int sec) { cout << n; wait_sec(sec); nextLine(); } // Creative Printing Methods with Graphical Effects void Console::drawLine() { for(int i = 1;i<20;i++) { print("-"); } nextLine(); } void Console::drawLine(int n) { for(int i = 1;i<n;i++) { print("-"); } nextLine(); } void Console::drawArrow() { print("-> "); nextLine(); } void Console::drawArrow(string text) { print("-> "+text); nextLine(); }Ich hoffe es ist nicht zu primitif für euch, ich bin nömlich noch anfänger.
Ich bin dankbar für alle eure Hilfen.
M.f.G. Developer_X
-
Da muss man nicht lange suchen

Diagram::~Diagram(void) { delete &item_labels; delete &item_values; delete &diagramChar; delete &title; delete &items; }Du löschst da im Destruktor von Diagram Objekte, die nicht zur Klasse gehören, sondern global sind (!) und zudem nicht einmal mit new angelegt worden sind (!!) - und deswegen knallt es auch.
Übrigens: Stringobjekte per konstanter Referenz übergeben, sonst wird jedesmal kopiert. Ebenso in getItems(): wenn du nichts lokales zurückgibst, ebenfalls eine konstante Referenz zurückgeben. Sonst kopierst du den ganzen Vektor, obwohl der Benutzer ja vielleicht nur mal size() aufrufen wollte.
Edit:
Und was ist das denn:
char* s = const_cast<char*>(text.c_str());Um const_cast einzusetzen, muss man schon einen sehr guten Grund haben und der liegt hier nicht vor. Schnell weg damit.
-
Das Problem war doch schon bei http://c-plusplus.net/forum/viewtopic-var-t-is-267862.html, du scheinst hier einen Denkfehler zu haben, Developer_X:
Objekte, die nicht dynamisch (pernew) angefordert werden, werden automatisch zerstört und dürfen nicht explizit freigegeben werden.
Insbesondere darfdeleteausschließlich auf Objekte angewendet werden, die pernewangefordert und nicht schon freigegeben wurden. Generell vermeidet man aber in C++ Fälle, wo explizites Speichermanagment notwendig ist, sondern regelt das in dafür ausgelegten Klassen (Beispiel: dynamisches Array ->vectorstattnew[]unddelete[]).
-
Hab mir die Fragen, etc. gar nicht angeguckt, aber dein Code ist mal total redundant. Du könntest verdammt viel Code vermeiden. Beispiel:
void Console::drawLine() { for(int i = 1;i<20;i++) { print("-"); } nextLine(); } void Console::drawLine(int n) { for(int i = 1;i<n;i++) { print("-"); } nextLine(); }Wie wäre es damit?
void Console::drawLine() { drawLine(20); } void Console::drawLine(int n) { for(int i = 1;i<n;i++) { print("-"); } nextLine(); }Und wenn wir schon dabei sind...
void Console::drawLine(int n = 20) { for(int i = 1;i<n;i++) { print("-"); } nextLine(); }Fertig. Na ja, egal

-
Außerdem zeichnet die Funktion n-1 Striche. Absicht?
-
Och danke, ich bin noch ein sehr starker Anfänger in C++. Ihr habt wirklich mit allem Recht, ich könnte viel Platzt sparen.
Danke sehr, Developer_X