我正在尝试使用std :: max_element找到向量的最大值.当我运行程序时,我得到一个分段错误,我认为这与std :: end越过向量的末尾有关吗?我已经尝试将其更改为std :: end(tempdata)-1)但无济于事.
auto max = std::max_element(std::begin(tempdata), std::end(tempdata));
std::ofstream maxcurrent("maxcurrent.txt", std::ios::app);
maxcurrent << v << std::setw(15) << *max << std::endl;
Run Code Online (Sandbox Code Playgroud)
看了这个答案,我不明白为什么我的工作不起作用.