#include <sstream>
#include <string>
using namespace std;
void fRec(int i) {
if (i == 0) {
return;
}
fRec(i - 1);
ostringstream s;
}
int main(int argc, char *argv[]) {
fRec(50000);
return 0;
}
運行時,這將產生:C++ - 字符串流在遞歸函數
Segmentation fault (core dumped)
回溯從GDB:
#0 0x000000000040064f in fRec (i=<error reading variable: Cannot access memory at address 0x7fffc75a6f5c>) at strstr.cpp:6
#1 0x000000000040066e in fRec (i=28182) at strstr.cpp:11
#2 0x000000000040066e in fRec (i=28183) at strstr.cpp:11
#3 0x000000000040066e in fRec (i=28184) at strstr.cpp:11
#4 0x000000000040066e in fRec (i=28185) at strstr.cpp:11
#5 0x000000000040066e in fRec (i=28186) at strstr.cpp:11
...
我想問一下爲什麼會這樣 - 如果我創建一個字符串對象而不是ostringstream,一切都結束了。在我看來,是否一次不能有太多的stringstream實例?
感謝澄清
感謝澄清傢伙! – Ferrard