Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在C+;中使用std::basic_ifstream::get()时发生AccessViolationException+/克利,为什么?_C++_Visual C++_C++ Cli_Access Violation_Visual Studio 2013 - Fatal编程技术网

C++ 在C+;中使用std::basic_ifstream::get()时发生AccessViolationException+/克利,为什么?

C++ 在C+;中使用std::basic_ifstream::get()时发生AccessViolationException+/克利,为什么?,c++,visual-c++,c++-cli,access-violation,visual-studio-2013,C++,Visual C++,C++ Cli,Access Violation,Visual Studio 2013,当我尝试运行此命令时: #include <tchar.h> #include <fstream> int _tmain(int argc, TCHAR *argv[]) { std::basic_ifstream<TCHAR> file("TestInput.txt"); file.get(); } 为什么会发生这种情况,以及在尝试读取文件时如何避免这种情况?这是因为我是使用\u DEBUG宏(从本机转换之前留下的)进行编译的。 删除它解

当我尝试运行此命令时:

#include <tchar.h>
#include <fstream>

int _tmain(int argc, TCHAR *argv[])
{
    std::basic_ifstream<TCHAR> file("TestInput.txt");
    file.get();
}

为什么会发生这种情况,以及在尝试读取文件时如何避免这种情况?

这是因为我是使用
\u DEBUG
宏(从本机转换之前留下的)进行编译的。
删除它解决了问题。

听起来好像宏在做意外的事情。当您需要了解VisualC++中发生的事情时,请将其转储到预处理器输出。关于做这件事的细节都有记录。

为什么我觉得这件事不会发生在我身上:/@chris:是的,我也有同样的感觉,不知道为什么。。。你在VS 2013上吗?是的,虽然我没有创建该文件,所以我不妨试试。呃,不,我还是不能得到一个异常。@chris:没关系,因为某种原因,我也不能让它重新运行。(我在另一个项目中将它作为_tmain()的第一行进行了测试,但我想肯定是其他东西先运行了…)我会缩小范围,感谢您让我知道。
\u DEBUG
符号是如何导致此异常的?
ntdll.dll!_RtlpWaitOnCriticalSection@8()  + 0xae bytes  
ntdll.dll!_RtlpEnterCriticalSectionContended@4()  + 0xa1 bytes  
ntdll.dll!_RtlEnterCriticalSection@4()  - 0x1f885 bytes 
msvcr120.dll!__lock_file()  + 0x2ce45 bytes 
[Managed to Native Transition]  
MyProject.exe!std::basic_filebuf<char,std::char_traits<char> >::_Lock() Line 355    C++
msvcp120d.dll!std::basic_istream<char,std::char_traits<char> >::_Sentry_base::_Sentry_base()  + 0x55 bytes  
msvcp120d.dll!std::basic_istream<char,std::char_traits<char> >::sentry::sentry()  + 0x32 bytes  
msvcp120d.dll!std::basic_istream<char,std::char_traits<char> >::get()  + 0x5c bytes 
[Managed to Native Transition]  
MyProject.exe!wmain(int argc = 0x2, wchar_t** argv = 0x054AA3F8) [line # removed]   C++
MyProject.exe!__tmainCRTStartup()    [line # removed]   C
[Managed to Native Transition]  
mscoreei.dll!__CorExeMain@0()  + 0x71 bytes 
mscoree.dll!_ShellShim__CorExeMain@0()  + 0x227 bytes   
mscoree.dll!__CorExeMain_Exported@0()  + 0x8 bytes  
ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes   
ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes