2

When I try to read string s with s.length() ~ 10000 with this code below. My output is 4094. How can I increase input buffer size?

string s;
cin >> s;
cout << s.length();
Anshika Singh
  • 994
  • 12
  • 20
lbelkov
  • 29
  • 4
  • 3
    The string size is only limited by your platform architecture. The `cin >> s;` will read until it encounters a whitespace character (tab, newline, space, return, etc). Does your input have whitespace characters? – Eljay Mar 26 '21 at 17:06
  • 1
    It's most likely that the 4095-th character is a whitespace character. – R Sahu Mar 26 '21 at 17:06
  • @Eljay No whitespaces. I have n strings each new in a new line – lbelkov Mar 26 '21 at 17:09
  • 3
    How are you getting 4K characters into the console? – SergeyA Mar 26 '21 at 17:19
  • 1
    @SergeyA: Actually, content of a text file might be redirected to the **STDIN**. From the command prompt: `type sometext.txt | program.exe` or `program.exe < sometext.txt`. My text file contains 5829 characters. Therefore the code above printed **5829**. – Jackdaw Mar 26 '21 at 20:03
  • 1
    @fpmBelkov newline is considered a whitespace – bolov Mar 26 '21 at 20:50
  • @SergeyA a redirection or a pipe can give you "infinite" input without any typing – phuclv Mar 26 '21 at 22:54
  • @SergeyA it DNA strands. I'm trying to create data structure for them with ropes – lbelkov Mar 27 '21 at 00:50

0 Answers0