小编Scy*_*Scy的帖子

如何从具有多个对象类型的集合中仅读取类型的特定对象

我有一个包含两种对象类型的集合.我想只将两种类型之一读入一个新的Set.这样做有一种优雅的方式吗?

java object hashmap set hashset

6
推荐指数
1
解决办法
69
查看次数

如何在C++中在运行时创建和增加数组的大小

我想创建一个数组,其大小我只会在运行时知道,然后在执行程序时进一步增加该大小.
这是来自/ r/dailyprogrammer挑战,可以在这里找到https://www.reddit.com/r/dailyprogrammer/comments/3twuwf/20151123_challenge_242_easy_funny_plant/
MSVisual给我错误std :: badd_array_new_length这意味着它在实例化时遇到问题阵列?
我很累,经常在网站上复制代码信,但是我经常出错.Visual是学习C++的糟糕平台吗?我应该试试QT吗?

#include <iostream>
#include <string>
void main(int argc, char* argv[]) {

    int currentPlants = std::stoi(argv[2]), targetPeople = std::stoi(argv[1]), currentProduce = 0, week = 0;
    int * plants;
    plants = new int[currentPlants];
    for (int i = 0; i < currentPlants; i++) {
        plants[i] = 0;
    }

    if (plants == nullptr) EXIT_FAILURE;

    while (currentProduce < targetPeople) {
        currentProduce = 0;
        for (int i = 0; i < currentPlants; i++) {
            currentProduce += plants[i];
            plants[i]++;
        } …
Run Code Online (Sandbox Code Playgroud)

c++ arrays

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

标签 统计

arrays ×1

c++ ×1

hashmap ×1

hashset ×1

java ×1

object ×1

set ×1