String Error

Viper2009

Erfahrenes Mitglied
Hallo ich habe ein code gefunden aber irgend wie will der nicht gehen. Und zwar will ich das er eine datei öffnet, sich die ID merkt und in den Ordner "database\\playerchars" die ID.xml dan löscht.

(840) case 3 : // delete char
{
PAccount *Acc = Client->GetAccount();
u8 Num = Packet[PacketSize-1];
if(Acc)

{
u32 CharID = Acc->GetChar(Num);
Acc->RemoveChar(Num);

if(CharID!=0)
{

(853) string path = "database\\playerchars";
(854) string path += "\\";
(855) string path += CharID;
(856) string path += ".xml";

(858) if (remove(path.c_str()))
Console->Print("%s Charakter ist gelöscht!", CharID);
else
Console->Print("%s Charakter ist nicht gelöscht!", CharID);

}
}
(865) return (true);
}

Und zwar bekomme ich diese Fehler:

(853): error C2065: 'string' : undeclared identifier
(853): error C2146: syntax error : missing ';' before identifier 'path'
(853): error C2065: 'path' : undeclared identifier
(854): error C2146: syntax error : missing ';' before identifier 'path'
(854): error C3861: 'string': identifier not found, even with argument-dependent lookup
(854): error C3861: 'path': identifier not found, even with argument-dependent lookup
(855): error C2146: syntax error : missing ';' before identifier 'path'
(855): error C3861: 'string': identifier not found, even with argument-dependent lookup
(855): error C3861: 'path': identifier not found, even with argument-dependent lookup
(856): error C2146: syntax error : missing ';' before identifier 'path'
(856): error C3861: 'string': identifier not found, even with argument-dependent lookup
(856): error C3861: 'path': identifier not found, even with argument-dependent lookup
(858): error C2228: left of '.c_str' must have class/struct/union type
(858): error C3861: 'path': identifier not found, even with argument-dependent lookup

Obwohl ich #include <string> habe.
wo ist da der fehler? Benutze Win.
 
Der Fehler ist das fehlende std:: vor dem string. Die STL-Container sind allesamt in dem Namespace std verpackt um Kollisionen zu vermeiden. Also entweder in der .cpp-Datei (NICHT IN DER HEADER-DATEI) ein using namespace std einsetzen oder besser, immer std::string schreiben.
 
danke für deine Porst ich werde dies gleich mal versuchen.
Mhh habe es jetzt so gemacht:

std::string path = "database\\playerchars";
std::string path += "\\";
std::string path += CharID;
std::string path += ".xml";

und bekomme so ein fehler:

error C2143: syntax error : missing ';' before '+='
error C2086: 'std::string path' : redefinition
error C2143: syntax error : missing ';' before '+='
error C2086: 'std::string path' : redefinition
error C2143: syntax error : missing ';' before '+='
error C2086: 'std::string path' : redefinition
 
so habe den fehler selber rausgefunden obs geht weis ich nicht:

std::string path = "database\\playerchars";
std::string (path += "\\");
std::string (path += CharID);
std::string (path += ".xml");
 
Du darfst beim += path nicht neu definieren:

std::string path = "database\\playerchars";
path += "\\";
path += CharID;
path += ".xml";
 
Ok ich habe das so gemacht, aber das Programm störzt da bei ab und die datei ist nicht gelöscht. Wo ran kann das liegen?
 
Das Programm stürzt vermutlich vor dem remove ab. Das klingt nach einem guten Fall für den Debugger.

An welcher Stelle genau kommt der Absturz? Hast du dir den zusammengesetzten String ausgeben lassen?
 
keine ahnung was du meinst aber ein debugger habe ich drin, er sagt mir das

Die exe sagt so was :

Unhandled exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
und wenn ich dan die exe schließe sagt er mir das :

...............
'Projekt-NC.exe': Loaded 'C:\WINDOWS\system32\MsgPlusLoader.dll', No symbols loaded.
'Projekt-NC.exe': Loaded 'C:\WINDOWS\system32\wshtcpip.dll', No symbols loaded.
First-chance exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
Unhandled exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
First-chance exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
Unhandled exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
First-chance exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
Unhandled exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
First-chance exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
Unhandled exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
First-chance exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
Unhandled exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
First-chance exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
Unhandled exception at 0x0053f6ec in Projekt-NC.exe: 0xC0000005: Access violation reading location 0x00000001.
The program '[6224] Projekt-NC.exe: Native' has exited with code 0 (0x0).

Und weist mich zu dieses datei :

void PConsole::print(const char *Fmt, ...)
{
static char Str[2048];
va_list args;
va_start(args, Fmt);
(X) _vsnprintf(Str, 2047, Fmt, args);
va_end(args);

(X) das ist der Courser dan kannst du dich mal bei mir melden icq: 3337935833 oder msn:dennisboh@msn.com
 
Zurück