My programs needs to read up to 50k character long strings from stdin. The code is as follows:
#include <iostream>
#include <string>
std::string A;
int main(){
std::cin >> A;
std::cout << "String max: " << A.max_size() << std::endl;
std::cout << "Size: " << A.size();
When I try to enter a 10k character long string I get the following output:
String max: 4611686018427387903
Size: 4095
According to Google both std::cin
and std::string
should have no problem handling 10k characters, but for some reason A
gets truncated after 4095 characters. I entered the string by pasting it into the default Ubuntu terminal. Pasting it into Python3 in the same terminal works fine, which leads me to believe that it's not the terminal that's truncating it, but C++. I compiled with g++ program.cxx
and I have 16 GB of RAM.
How can I enter large strings from stdin? Any help is appreciated.
P.S.: If you need a large string just paste this into Python: print("123"*5000)