c++中可以作为输入的字符数组的最大长度是多少?
What is maximum length of character Array which can be taken as input in C++?
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char s[100000];
cin>>s;
cout<<strlen(s);
return 0;
}
在这个程序中,字符数组接受长度为4095的输入。大于这个长度,它不需要输入。请提供此问题的原因
当您在本地声明char s[MAX_SIZE]
时,它将被存储在stack
区域中,该区域与它相关联的内存量有限。
但是,如果你声明它是globally
,那么它的大小可以增加到几乎剩下的内存在你的PC。或者使用std::string
来解决MAX_SIZE的问题。
相关文章:
- C++,数组有多少个地址?
- 在二维向量或数组中可以存储的最大元素数是多少?
- 如何创建一个所有行大小不同的 2D 数组,并且用户将指定每行将有多少个元素?
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- 在 C++ AMP 数组中复制数据多少次?
- C++ 检查结果数组中有多少次数字
- 将数组的元素插入映射的时间复杂度是多少?
- 当我们不使用空字符显式初始化字符数组时,字符串的长度是多少?
- 我怎么知道数组包含多少个元素C++?
- 数组由其类自己的指针指向的大小是多少?
- c++ 中堆上数组的默认值是多少?
- 如何知道我想在数组中存储多少索引
- 我们可以在 C++ 编程中使用的二维数组的最大大小是多少?
- 指针数组中将有多少内存分配
- C++如何打印在2数组中重复多少个元素
- 找出数组中有多少不同的浮点值
- 在计算使用了多少个数组索引的同时,如何填充一个来自用户输入的字符的数组?(使用cin.get)
- 如果我自己不分配数组元素,数组元素的值是多少
- 遍历二维数组的时间复杂度是多少
- 我的数组的长度是多少