Muh*_*eeb 6 c++ gcc cygwin mingw
非常奇怪的行为发生在我身上.我在Windows 7 64位上分别使用最新的Cygwin32,Cygwin64和MinGW32以及GCC 4.9.2,4.9.2和4.8.1.我也在使用GCC 4.8.2在32位Linux上进行测试.
所以在所有系统上都可行
#include <bits/stdc++.h>
using namespace std;
string s,t;
int main(){
cin>>s>>t;
cout<<s;
}
Run Code Online (Sandbox Code Playgroud)
这很有效
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
string s="a",t="b";
int main(){
cin>>s>>t;
cout<<s;
}
Run Code Online (Sandbox Code Playgroud)
但是在上面提到的3种配置中输入第一个字符串后,下一个在Windows上崩溃,但在Linux上正常工作:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
string s,t;
int main(){
cin>>s>>t;
cout<<s;
}
Run Code Online (Sandbox Code Playgroud)
显然,唯一的区别是字符串在输入之前是空的,并且_GLIBCXX_DEBUG已启用.
首先,这是一个可重现的问题吗?即它是在具有相同配置的每台PC上发生的,还是只发生在我的PC上?第二,问题是什么?我该怎么办?我显然需要 _GLIBCXX_DEBUG在代码中调试其他STL结构.
_GLIBCXX_DEBUG更改 STL 类的 ABI(即结构布局,包括流和std::string):
To use the libstdc++ debug mode, compile your application with the compiler
flag -D_GLIBCXX_DEBUG. Note that this flag changes the sizes and behavior of
standard class templates such as std::vector, and therefore you can only link
code compiled with debug mode and code compiled without debug mode if no
instantiation of a container is passed between the two translation units.
Run Code Online (Sandbox Code Playgroud)
(来自官方文档)。
您的应用程序(使用 编译_GLIBCXX_DEBUG)传递std::string到std::cin::operator >>in libstdc++.dll(不使用此宏编译),因此违反了上述要求。此类违规通常表现为运行时崩溃:请参阅此或此以获取具体示例。
| 归档时间: |
|
| 查看次数: |
305 次 |
| 最近记录: |