Access violation error with ioStream
I am creating an ioStream and then using an operator overloaded in a dll:
std::istrstream wStream((char *)aString,strlen(aString));
wStream >> wValue;
aString is a const char* received as a parameter. The second line causes this runtime error:
0xC0000005:Access Violation reading location 0x00000020
However, when I replace the second line with the actual code of the operator overload function, I get no error.
Note that I am building this in Visua开发者_StackOverflow中文版l Studio 2010, and the same code runs with no error when compiled with Visual Studio 2005.
It's hard to tell without context about how aString
is set but istrstream
is a deprecated class. Have you considered trying istringstream
instead as a test to help narrow things down?
std::istringstream wStream(std::string(aString));
wStream >> wValue;
EDIT: upon further consideration this looks suspiciously like your aString
is actually null, and as the strstream
tries to read from it, eventually it dies to an access violation. Try printing out the raw pointer value of aString
prior to doing the string stream operations (something like std::cout << static_cast<void*>(aString) << std::endl;
)
精彩评论