I want to let the users input strings with more than 4,095 characters, but std::cin
/std::istream
seems to have some sort of undocumented limit and keeps cutting off the string to only allow 4,095 characters.
Is there some way to get past this "limit" using one of the many input functions, preferably allowing any length? There might not be a limit in the cpp standard, but the operating system I am currently using may have an input buffer limit - Arch Linux.
The strings may reach lengths of 1 ≤ L ≤ 10e6
where L
is the length of the string.
int main() {
/* The user inputs a string with more than
4095 characters.
Let's say that every character in the string
is 'a' except for the 4095th character in the
string, which is 'B', and the end of the string
looks like "...aaBaaaaaaaaaaaaa"
The string will get cut off to "...aaB" (4095
characters) meaning that there seems to be some
sort of limit. */
std::string str;
/* Manually paste a string that has 10,000
characters into a terminal emulator (Alacritty)
with CTRL+C → SHIFT+INSERT */
std::cin >> str;
/* This next line is supposed to output 10,000,
but instead, it outputs 4,095. */
std::cout << str.length() << std::endl;
}
The provided example should be simple enough to understand without needing a better reproducible example. Providing a better example would only clutter the post with a lot of unneccessary information since it should be simple enough as it is.
The input data I give it looks like this aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
but imagine 10,000 a's and it does not have any whitespaces.
Note: This program is compiled with this command:
g++ -g -O2 -std=gnu++17 -static light.cpp && ./a.out