Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 向向量数组添加元素_C++_Arrays_Loops_Vector - Fatal编程技术网

C++ 向向量数组添加元素

C++ 向向量数组添加元素,c++,arrays,loops,vector,C++,Arrays,Loops,Vector,所以我很难将通过循环找到的除数加到向量数组中 #include <iostream> #include <vector> using namespace std; vector <int> numbers; bool isSummableNumber(int num) { for (int i=1; i<=num; i++) { if (num%i==0) {

所以我很难将通过循环找到的除数加到向量数组中

#include <iostream>
#include <vector>

using namespace std;

vector <int> numbers;

bool isSummableNumber(int num)
{
    for (int i=1; i<=num; i++)
    {
        if (num%i==0)
            {
                 // this is where I need to send them to the array 
            }
    }
#包括
#包括
使用名称空间std;
向量数;
布尔isSummableNumber(整数)
{

对于(int i=1;i您是否尝试过:
数字。向后推(num)

对于向
向量添加元素,您只需调用:

vector_name.push_back( element_value );
因此,在你的情况下:

bool isSummableNumber(int num)
{
    for (int i=1; i<=num; i++)
    {
        if (num%i==0)
            {
                 numbers.push_back( num );
            }
    }
}
bool isSummableNumber(int num)
{

对于(inti=1;isee@bolov:push_back
“coulding”到底是怎么回事?你只是在讽刺吗?我猜太微妙了。是的,我是在讽刺。