hi,
can some body say what is this error
I use Visual studio 2008 to compile.Unhandled exception at 0x64f3797f (msvcp90d.dll) in Exercise.exe: 0xC0000005: Access violation writing location 0x6d696873.
hi,
can some body say what is this error
I use Visual studio 2008 to compile.Unhandled exception at 0x64f3797f (msvcp90d.dll) in Exercise.exe: 0xC0000005: Access violation writing location 0x6d696873.
You had the exact same problem in your previous thread.
You can't cast a string's address to void* and expect something to come out of it. What is the reason that you are attempting such low level input? You might use a char* instead or read in junks to char* and append them to string or something like that.Code:string newPassword; ... fread(&newPassword, sizeof(string), 1, fp);
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
It means you did something very bad.
This code in itself is very, very bad.
You mix a lot of C and C++.
I believe the cause of the error is this line:
Never, EVER use C-style functions to read directly into a C++ object.Code:fread(&newPassword, sizeof(string), 1, fp);
thanks
I always forget to correct this
thanks
I always forget to correct this
what should I use instead of fread();
I'm trying to change a code that I wrote before in C to C++. in fact I'm practicing C++ by this.You mix a lot of C and C++.
> Unhandled exception at 0x64f3797f (msvcp90d.dll) in Exercise.exe: 0xC0000005: Access violation writing location 0x6d696873.
Since the address in question consists entirely of byte values which are printable, in this case "mihs", look for anywhere in your code where that string (or it's reverse) was typed in by you, or exists as string data in your code.
Basically, your string overwrote a pointer, then you tried to dereference it.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I used a different approach.
The error occured when exit was called, and it was inside the destructor of std::string. That tells me that there was some corruption in a global std::string (since there was no std::string in main).
I found only one, so I took its address and compared it to the address of "this" inside the destructor of std::string and sure enough - they matched.
So I set a data breakpoint on that address, and VS kindly breaked when the contents of the std::string was corrupted. It was inside fread, so I used the call stack to go back to the calling function and found the source of the error.
And as for what you should use - streams! You already use them in one part of the code.
I removed fread and use ifstream inClientFile instead, Now problem solved
thank you Elysia, Salem, anon
I hope your advance advices help me through learning C++