avr39ripe

cppStrFromCin

Oct 4th, 2021
896
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     char* str{ new char[100]{"Test string"} };
  6.     int num{};
  7.  
  8.     std::cout << "Original string: " << str << " length: " << strlen(str) << '\n';
  9.  
  10.     //std::cout << "Enter some number: \n";
  11.     //std::cin >> num;
  12.  
  13.     //std::cout << "Some number is : " << num << '\n';
  14.  
  15.     std::cin.ignore(100, '\n');
  16.  
  17.     std::cout << "Enter some string: \n";
  18.     std::cin.getline(str,99);
  19.  
  20.     std::cout << "Entered string: " << str << " length: " << strlen(str) << '\n';
  21.  
  22.     //std::cout << "Enter some string: \n";
  23.     //std::cin >> str;
  24.  
  25.     //std::cout << "Entered string: " << str << " length: " << strlen(str) << '\n';
  26.  
  27.     delete[] str;
  28.     return 0;
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
RAW Paste Data