小编mon*_*ony的帖子

在push_back cin不起作用之后

我有这个代码的问题:

int main()
{
    int x, sum = 0, how_many;
    vector<int> v;

    cout << "Write few numbers (write a letter if u want to end)\n";

    while (cin >> x)
    {
        v.push_back(x);
    }

    cout << "How many of those first numbers do u want to sum up?" << endl;
    cin >> how_many;

    for (int i = 0; i < how_many; ++i)
    {
        sum += v[i];
    }
    cout << "The sum of them is " << sum;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

问题是控制台不让我写入某些内容how_many …

c++

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

标签 统计

c++ ×1