使用linux和g++。
这是可行的:
stringstream ss;
for (int k = 1; k < 1000; k++){
}这也应该是可行的,但会导致“分段错误”:
for (int k = 1; k <1000; k++){
stringstream ss;
}为什么?
发布于 2019-07-26 04:06:01
感谢安东尼奥·佩雷斯的回复。
实际上,我的代码是这样的:
#pragma pack(1)
#include <sstream>
#include <iostream>
int main(){
for (int i = 0; i < 2; i++){
std::stringstream ss;
}
}令人惊讶的是,如果我像这样替换#杂注包(1):
#include <sstream>
#pragma pack(1)
#include <iostream>
int main(){
for (int i = 0; i < 2; i++){
std::stringstream ss;
}
}...then未出现错误!
为什么sstream不允许打包其结构,是否存在可能的(非bug)原因?
https://stackoverflow.com/questions/57206628
复制相似问题