终端中的用户输入被截断
user input in terminal is truncated
在下面的代码中:
#include <iostream>
#include <string>
using namespace std;
int main() {
string my_str;
cout << "Enter a large string:" << endl;
getline (cin, my_str);
cout << my_str << endl;
return 0;
}
当输入一个大字符串(没有任何空格)时,只打印前 4095 个字符。为什么? (Ubuntu 14.4,g++ 4.9.3)
谢谢。
在Linux下,终端一次可以读取的最大字符数由内核源码中的N_TTY_BUF_SIZE决定。值为 4096.
在下面的代码中:
#include <iostream>
#include <string>
using namespace std;
int main() {
string my_str;
cout << "Enter a large string:" << endl;
getline (cin, my_str);
cout << my_str << endl;
return 0;
}
当输入一个大字符串(没有任何空格)时,只打印前 4095 个字符。为什么? (Ubuntu 14.4,g++ 4.9.3)
谢谢。
在Linux下,终端一次可以读取的最大字符数由内核源码中的N_TTY_BUF_SIZE决定。值为 4096.