-3

I wanted to read huge input as a sting but it doesn't work on my linux box. When I tried to insert string ( huge) , it stopped me to add any character once I reached 2998 character.

std::string s;
std::cin.clear();
cout<< "Enter string"<<endl;;
getline(cin, s);

So I decided to add the huge string in a file and read from there. Now I have a file which contains only a single line , how would I print the string ( getline() doesn't work because it can not read more than 2998 bytes in my linux system ).

For example I have following input ( part of a file),

cat\n\ndog\ts\n\n\nmarket\g\he\n

Output should be:

cat
dog\ts
market\g\he

Appreciate your help.

  • 1
    You could use `std::istream::get()` to read the string char by char. – DimChtz Jul 14 '16 at 19:47
  • 1
    You have drawn an incorrect conclusion -- it is not `std::getline()` with the limit, it is your terminal! That said, reading a massive string sounds like a design error. What exactly are you trying to do? – Dúthomhas Jul 14 '16 at 19:47
  • 1
    Where is this 2998 bytes limitation coming from ? The next obvious solution is to read in chunks and do some minor processing before printing it out line by line. – Arunmu Jul 14 '16 at 19:47

1 Answers1

1

Can't you do something similar to this with ifstream?

BUFFER_MAX = 3000; //Whatever you want to be
char[BUFFER_MAX] buffer;
std::cin.getline(buffer,BUFFER_MAX-1);

This is just from going off of this documentation: std::istream::getline().

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Taztingo
  • 1,915
  • 2
  • 27
  • 42