首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在字符串数组中存储更多的字符串

如何在字符串数组中存储更多的字符串
EN

Stack Overflow用户
提问于 2013-02-25 18:13:00
回答 2查看 142关注 0票数 0
代码语言:javascript
运行
复制
#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;
}

我想把我所有的排列都存储在一个字符串数组中,但是我不能存储>8!(40320) i.9!接着,如果我声明string a1000000,它在dev c++中出现错误,任何人都可以解释如何将其存储为字符串数组(因为我希望在另一段代码中存储这个字符串代码,使其更容易)大于9!或者最多15岁!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-02-25 18:15:40

堆栈溢出。

对于这样数量的元素来说,堆栈太小了。您需要使用堆(使用operator new)。或者只使用std::vector

例如,您可以替换

代码语言:javascript
运行
复制
string a[1000000];

使用

代码语言:javascript
运行
复制
std::vector< std::string > a( 1000000 );

long int也是如此。

票数 4
EN

Stack Overflow用户

发布于 2013-02-25 19:32:17

写到一个文件,定期冲洗它。在内存中缓存所需的少量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15073550

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档