c++中可以作为输入的字符数组的最大长度是多少?

What is maximum length of character Array which can be taken as input in C++?

本文关键字:多少 数组 字符 输入 c++      更新时间:2023-10-16
#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的问题。