错误:'System.Runtime.InteropServices.SEHException'
error: 'System.Runtime.InteropServices.SEHException'
>我正在尝试以这种方式打开一个文件,但在标记的行上出现异常:
std::string str = "c:/qsdqsdsq/qsdqsdsq/qsdqsd.txt+++++qsdqsdqsd";
FILE *abc = fopen(str.substr(0, str.find_first_of("+++++")).c_str(), "w+b"); // marked line
例外:
类型的未处理异常 "System.Runtime.InteropServices.SEHException"发生在项目中.exe
其他信息:外部组件引发异常。
调试器指向xstring
文件的第 2296 行(仅包含_Xout_of_range("invalid string position");
行之后的}
)。
请问我该如何解决这个问题?
多谢!
如果start
不在[0, str.length)
范围内或start + length
不在[0, str.length]
范围内,则会引发此异常。由于start
为 0,并且find_first_of
返回有效的索引或std::string::npos
如果在这种情况下找不到任何字符,则表示std::string::npos
是由 find_first_of
返回的。由于您发布的代码无法做到这一点,因此我假设您发布的不是导致异常的实际代码。
相关文章:
- 如何传递InteropServices.ComTypes.IStream到接受IStream*的本机方法,使用c++/c
- OPENCV CV ::减去方法投掷System.Runtime.InterOpservices.sehexceptio
- OpenCV: System.Runtime.InteropServices.SEHException
- 什么是类型为"System.Runtime.InteropServices.SEHException"的未处理异常
- OpenCV 代码中'System.Runtime.InteropServices.SEHException'未处理的异常
- 错误:'System.Runtime.InteropServices.SEHException'