我有一个包含两种对象类型的集合.我想只将两种类型之一读入一个新的Set.这样做有一种优雅的方式吗?
我想创建一个数组,其大小我只会在运行时知道,然后在执行程序时进一步增加该大小.
这是来自/ 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)