Answer the question
In order to leave comments, you need to log in
How to fix Stack Overflow when recursing using std::thread and templates?
Code below:
#include <iostream>
#include <algorithm>
#include <locale>
#include <exception>
using namespace std;
double last_pos = 0x00;
int N = 0x00;
void str_cut()
{ ++last_pos; // падает на == 3805
if (last_pos > 64*1024) {
return; // exit condition
}
else {
try {
str_cut(); // Move semantics ONLY!
}
catch (std::exception const& e) {
throw exception{};
cerr << "Stack Overflow detected!" << /*e << */endl;
}
}
}
int main()
{
try {
// UTF-8 settings here
setlocale(LC_ALL, "");
setlocale(LC_ALL, "rus");
std::cout.flush();
str_cut();
system("pause");
return 0;
}
catch (...) {
// stack overflow exception handling
throw exception{};
cerr << "Stack Overflow detected!" << /*e << */endl;
}
}
while(last_pos < 65535) str_cut();
Answer the question
In order to leave comments, you need to log in
I didn’t read the algorithm, but if I understand correctly, the smaller N, the greater the recursion depth, hence the stack overflow. It's not about the input sequence, but about local variables and function arguments. So change to cycle.
As for Access Denied and others, most likely there are other errors.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question