简体   繁体   English

ioStream访问冲突错误

[英]Access violation error with ioStream

I am creating an ioStream and then using an operator overloaded in a dll: 我正在创建ioStream,然后使用dll中重载的运算符:

  std::istrstream wStream((char *)aString,strlen(aString));
  wStream >> wValue;

aString is a const char* received as a parameter. aString是作为参数接收的const char *。 The second line causes this runtime error: 第二行导致此运行时错误:

0xC0000005:Access Violation reading location 0x00000020 0xC0000005:访问冲突读取位置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 Visual Studio 2010, and the same code runs with no error when compiled with Visual Studio 2005. 请注意,我正在Visual Studio 2010中构建它,并且使用Visual Studio 2005编译时,相同的代码运行没有错误。

It's hard to tell without context about how aString is set but istrstream is a deprecated class. 没有上下文很难讲述aString的设置方式,而istrstream是不推荐使用的类。 Have you considered trying istringstream instead as a test to help narrow things down? 您是否考虑过尝试使用istringstream作为帮助缩小范围的测试?

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. 编辑:经过进一步考虑,这看起来像您的aString实际上是空的,并且当strstream尝试从中读取时,最终它死于访问冲突。 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; ) 尝试在执行字符串流操作之前打印出aString的原始指针值(类似std::cout << static_cast<void*>(aString) << std::endl;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM