C++ 如何在字符串数组中存储更多数量的字符串 #包括 #包括 #包括 使用名称空间std; int main() { std::向量v; 长整数a1[1000000]; 字符串a[1000000]; 对于(int i=0;i n; 对于(int i=0;i>a1[i]; v、 推回(a1[i]); } 排序(v.begin(),v.end()); char-ch[100]; int i=0; 做{ 对于(int j=0;j

C++ 如何在字符串数组中存储更多数量的字符串 #包括 #包括 #包括 使用名称空间std; int main() { std::向量v; 长整数a1[1000000]; 字符串a[1000000]; 对于(int i=0;i n; 对于(int i=0;i>a1[i]; v、 推回(a1[i]); } 排序(v.begin(),v.end()); char-ch[100]; int i=0; 做{ 对于(int j=0;j,c++,string,vector,C++,String,Vector,堆栈溢出) 堆栈太小,无法容纳如此多的元素。您需要使用堆(使用operator new),或者只使用std::vector 例如,您可以替换 #include<iostream> #include<vector> #include<algorithm> using namespace std; int main() { std::vector<int> v; long int a1[1000000]; string a[1

堆栈溢出)

堆栈太小,无法容纳如此多的元素。您需要使用堆(使用
operator new
),或者只使用
std::vector

例如,您可以替换

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
    std::vector<int> v;
    long int a1[1000000];
    string a[1000000];
    for (int i=0; i<100; i++)
        a[i]=" ";
    int n;
    cout << "enter the value of n";
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> a1[i];
        v.push_back(a1[i]);
    }
    sort(v.begin(), v.end());
    char ch[100];
    int i=0;
    do { 
        for(int j=0; j<n; j++)
        {
            ch[j] = v[j] + '0';
            // cout<<ch[j];
        }
        int j=3;
        int k=0;
        for(int l=0; l<n; l++)
        {
            a[i] = a[i] + ch[l];
        }
        cout << a[i] << endl;
        i++;
    }
    while (std::next_permutation(v.begin(), v.end()));
    cout << endl << i;
}

std::vectora(1000000);
对于长整型

堆栈溢出也是如此

堆栈太小,无法容纳如此多的元素。您需要使用堆(使用
operator new
),或者只使用
std::vector

例如,您可以替换

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
    std::vector<int> v;
    long int a1[1000000];
    string a[1000000];
    for (int i=0; i<100; i++)
        a[i]=" ";
    int n;
    cout << "enter the value of n";
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> a1[i];
        v.push_back(a1[i]);
    }
    sort(v.begin(), v.end());
    char ch[100];
    int i=0;
    do { 
        for(int j=0; j<n; j++)
        {
            ch[j] = v[j] + '0';
            // cout<<ch[j];
        }
        int j=3;
        int k=0;
        for(int l=0; l<n; l++)
        {
            a[i] = a[i] + ch[l];
        }
        cout << a[i] << endl;
        i++;
    }
    while (std::next_permutation(v.begin(), v.end()));
    cout << endl << i;
}

std::vectora(1000000);

对于长int

写入文件也一样,定期刷新它。
将所需的少量缓存在内存中。

写入文件并定期刷新。
将所需的少量缓存在内存中。

您想在一个容器中最多存储
15!
字符串吗?您确定您知道这有多大以及需要多少存储空间吗?@使用容器的高炉可能需要大内存,我想要10^15的存储空间,就像我想做的那样,拿出一个计算器,估计一下RAM/addre的数量超过1.3万亿的
std::string
对象及其内容需要ss空间。如果您是为了解决spoj问题而这样做的,您可能正在尝试一种荒谬的不切实际的暴力解决方案。您想在一个容器中最多存储
15!
字符串?您确定知道它有多大以及需要多少存储空间吗uire?@使用容器的高炉可能需要大内存,我想要高达10^15的存储空间,就像我在做spoj时想要的那样,拿出一个计算器,估计超过1.3万亿的
std::string
对象及其内容需要多少RAM/地址空间。如果你是为了一个spoj问题而这样做的话,你可能是在尝试一个荒谬的方法不切实际的暴力解决方案。我认为堆也不够15!@meh使用容器可能需要大内存,我希望最多10^15个存储空间有吗alternative@user1670364-你应该做一些研究。这有不同的技术。而且,这取决于你想做什么。这是一项复杂的任务。我不认为堆足够15个!@meh使用容器可能需要大内存,我希望最多10^15个存储空间有吗alternative@user1670364-你应该做一些研究。这有不同的技术。而且,这取决于你想做什么。这是一项复杂的任务。
std::vector< std::string > a( 1000000 );