如何声明类元素百万C ++ [英] how to declare class with 1000000 elements c++

查看:118
本文介绍了如何声明类元素百万C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个C ++ code和我需要的是申报有两个elments为

I am writing a c++ code and my need is to declare a class having two elments as

class arr{
    public:
        long num;
        string str;
};

现在我需要存储近百万elments这个类的(取决于一系列的1 LT类对象可以warry用户输入的号码; = N< = 1000000
对象是动态创建为

now i need to store almost 1000000 elments of this class(depending on user input number of class object can warry in a range of 1 <= n <= 1000000 The object are created dynamically as

#include <iostream>
#include<string>

using namespace std;

class arr{
    public:
        long i;
        string str;
};

int main(){
    long n,j,i;
    cin>>n;
    arr a[n];

....计划休息

.... rest of programme

但如果n的值很大,然后100000然后程序挂起,但工作正常的值小于100000我应该尝试在走我试着解决问题二维数组,它是划分ARRA帮助申报超过10万的对象有什么办法在两部分。

but if value of n is large then 100000 then programs hang but works fine for value less then 100000 what approach should i try to declare more than 100000 objects in a go i tried solving issue with help of 2D array that is dividing arra in two part

ARR一个[1000] [1000];

arr a[1000][1000];

但这种做法是不是为我工作

but this approach is not working for me

请,如果有人有任何想法就帮我这
在此先感谢

please if anybody have any idea do help me out with this thanks in advance

推荐答案

只需使用的std ::矢量

#include <iostream>
#include <vector>

int main(){
    long n;
    cin>>n;
    std::vector<arr> a(n);
}

这篇关于如何声明类元素百万C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆