小编Ji *_*i W的帖子

为什么std :: accumulate生成705032704作为输出而不是向量中元素的总和?

输出是705032704而不是5000000000。为什么?我以为std::accumulate可以计算向量中元素的总和。

#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <iterator>
#include <queue>
#include <stack>
#include <numeric>

typedef long long ll;

int main()
{

    std::vector<ll> nums = {1000000000, 1000000000,1000000000,1000000000,1000000000};
    std::cout << std::accumulate(nums.begin(), nums.end(), 0);
    std::cin.ignore();

}
Run Code Online (Sandbox Code Playgroud)

c++ algorithm stl overflow accumulate

9
推荐指数
2
解决办法
204
查看次数

为什么三元运算符返回 0?

为什么以下代码的输出为“0”?

#include <bits/stdc++.h>

int main() {
    int max = 5;
    std::cout << (false) ? "impossible" : std::to_string(max);
}
Run Code Online (Sandbox Code Playgroud)

c++ conditional-operator c++11

0
推荐指数
1
解决办法
81
查看次数