-1

In the following code:

#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;
}

When a large string (without any white spaces) is entered, only the first 4095 characters are printed. Why? (Ubuntu 14.4, g++ 4.9.3)

Thanks.

havij
  • 1,030
  • 14
  • 29
  • Your program ignores the command line... Are you asking about the command line or reading a string as input? Can you give a specific example (preferably with a link to it exhibiting this behaviour online)? – chris Aug 18 '16 at 00:18
  • Yes, I meant reading a string as input. – havij Aug 18 '16 at 00:23
  • 2
    This may be an issue with your terminal emulator limiting the size of input lines. What happens if you redirect the input to a file? – Barmar Aug 18 '16 at 00:30
  • try to get your data from a file indeed. read ifstream, it's very easy. – Miro Rodozov Aug 18 '16 at 00:55
  • @Barmar the same thing happens when I redirect it to file. I just found this [post](http://stackoverflow.com/questions/18015137/linux-terminal-input-reading-user-input-from-terminal-truncating-lines-at-4095), it seems you are right. Thanks. – havij Aug 18 '16 at 01:00
  • I don't understand. How can I be right if it fails the same way when input is from a file instead of the terminal? Did you redirect input or output? – Barmar Aug 18 '16 at 01:48
  • Have a try the answer in this question http://stackoverflow.com/questions/18015137/linux-terminal-input-reading-user-input-from-terminal-truncating-lines-at-4095 – Nayana Adassuriya Aug 18 '16 at 02:00
  • @Barmar I misunderstood, I redirected the input given by user to file. but you were right, when the input is redirected from file this doesn't happen. – havij Aug 18 '16 at 18:02

1 Answers1

1

Under Linux, the maximum number of characters that can be read in one go on a terminal is determined by N_TTY_BUF_SIZE in the kernel source. The value is 4096.

Rz_CHIFFRE
  • 46
  • 4