如何在字符串数组中存储更多数量的字符串
how to store more numbers of strings in an string array
#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(即9!以后,如果我声明字符串a〔1000000〕,它在dev c++中显示错误,任何人都可以解释我如何将它存储为大于9的字符串数组(因为我希望将此字符串代码存储在另一个代码中,这会更容易(吗!或高达15!
堆栈溢出。
堆栈太小,无法容纳这样数量的元素。您需要使用堆(使用operator new
(。或者只使用std::vector
。
例如,您可以更换
string a[1000000];
带有
std::vector< std::string > a( 1000000 );
与long int
相同。
写入一个定期刷新的文件。在内存中缓存所需的几个。
相关文章:
- 将C#字符串数组传递给C++
- 如何为 C 型字符串数组编写 getter 和 setter?
- 有没有办法使用 strcpy 将字符串数组复制到另一个字符串或其他数组中?
- 尝试将 c 字符串数组与分隔符连接起来
- 将字符串数组传递给接受常量字符**的函数
- 返回 C++ 中的字符串数组
- 如何从COM模块中的函数返回字符串数组?
- 无法将字符串数组声明为类成员而不是字符 (C++)
- 删除字符串数组
- 如何将字符串数组返回到 java JNI
- 将字符串数组作为函数参数传递
- C++将字符串数组的元素存储到变量中
- 循环访问还包含未使用元素的字符串数组
- 字符串数组上的 sizeof 运算符以 C++ 为单位给出不同的输出
- 乘以字符串/数组和全局数组
- 递归二进制搜索与字符串数组
- 如何初始化一个标准::字符串数组?
- 无法在声明时使用初始值设定项列表初始化常量字符*/字符串数组的向量
- C++字符串数组的动态向量
- 给定一个等长字符串数组