中断两年后,我一直在尝试重新回到 C++。第一天,一切都很顺利。但是当我第二天回来时,我的所有项目都cout无法编译。
错误是:
发生异常。分段故障
调试控制台给我:
Thread 1 received signal SIGSEGV, Segmentation fault.
0x00007ffd9109f436 in std::basic_ostream<char, std::char_traits<char> >::sentry::sentry (this=this@entry=0x5ffda0, __os=...) at /workspace/srcdir/gcc_build/x86_64-w64-mingw32/libstdc++-v3/include/bits/ostream.tcc:51
Run Code Online (Sandbox Code Playgroud)
这是我的代码示例,其中发生了这种情况:
#include <iostream>
using namespace std;
int main()
{
string abc = "a";
std::cout << "hi";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如前所述,错误发生在 上std::cout,std::string工作正常。std如果我使用命名空间然后只写入cout,或者如果我不使用命名空间并写入整个内容,则没有区别。
如果我尝试使用,也会发生同样的问题cin >> abc;
我正在使用 Visual Studio 代码。c_cpp_properties.json我不知道它是否相关,但我的文件夹中没有文件.vscode。然而,我得到了其余的,而且我确实有 C++ 插件。
这是在 Windows 上使用 g++ 的情况。
我努力了:
我希望你们中比我聪明的人能够找出问题所在。
编辑:我发现了问题,假设它是一个 …