fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8.  
  9. // a vector with a capacity of 100 chracters
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(NULL);
  12. vector<char> c(pow(10,2));
  13. cout << c.capacity() << endl;
  14. for(int i = 0; i < 4 ;i++)
  15. {
  16. cin >> c[i];
  17. }
  18. for(int i = 0; i < 4 ;i++)
  19. {
  20. cout << c[i];
  21. }
  22.  
  23.  
  24. // a vector with a capacity of 10^18 chracters
  25. vector<char> r(pow(10,18));
  26. //GIVES A RUNTIME ERROR I THINK std::bal_alloc meaning not sufficient memory
  27.  
  28. //where in memory is vector allocated space i think stack in this case
  29. cout << r.capacity() << endl;
  30. for(int i = 0; i < 4 ;i++)
  31. {
  32. cin >> r[i];
  33. }
  34. for(int i = 0; i < 4 ;i++)
  35. {
  36. cout << r[i];
  37. }
  38.  
  39. return 0;
  40. }
  41.  
Runtime error #stdin #stdout #stderr 0s 4284KB
stdin
1234
5678
stdout
100
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc