suppose i have to read characters in order of pow(10,18)
How to read a vector of characters from stdout or until user presses enter or not
First of all , you cannot read input from stdout.
stdout stands for standard output. You can print your output to stdout whereas read the input from the stdin ( standard input ).
As for reading the characters , you can use cin to input a string which would read the entire string or run a loop to take input till EOF.
Also since you want to take such large inputs , I would suggest you to use fast input-output for a better performance.
yes i know by mistake wrote it , stdin meant “in” means input from stdin. btw my doubt was reading a vector of characters from stdin wth capacity pow(10,18) but it gives a runtime error bad_alloc meaning it cannot allocate memory it has nothing to do with time http://ideone.com/4pD208 so how to read 10^18 size vector
@RishabhSingh
C++ simply does not allow you to create an array of size larger than 10^9. That is the maximum we can go , be it static allocation or dynamic. Since a vector too uses a dynamic array only , it gives a bad_alloc exception when you try to declare such a large array. It is simply not allowed in C++.
so is there any way to store something greater than 10^9 char arrays,strings or anything.
since the chewbacca problem says it can have 10^18
@RishabhSingh
10^18 means that the number is just 18 digits long. You can take its input in long long int variable or a string. Both would work and this problem can be solved either way.
I only said that you cannot make an array of size 10^18. But if you need to store a single number of order of 10^18 then you can just use a long long int variable or make an array of 18 size if you wish to store each digit seperately.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.