BHXSpecter

Framing Example

Jun 12th, 2013
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. // ask for a person's name, and generate a framed greeting
  2. #include <iostream>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7.     std::cout << "Please enter your first name: ";
  8.     std::string name;
  9.     std::cin >> name;
  10.    
  11.     // build the message that we indent to write
  12.     const std::string greeting = "Hello, " + name + "!";
  13.    
  14.     // build the second and fourth lines of the output
  15.     const std::string spaces(greeting.size(), ' ');
  16.     const std::string second = "* " + spaces + " *";
  17.    
  18.     // build the first and fifth lines of the output
  19.     const std::string first(second.size(), '*');
  20.    
  21.     // write it all
  22.     std::cout << std::endl;
  23.     std::cout << first << std::endl;
  24.     std::cout << second << std::endl;
  25.     std::cout << "* " << greeting << " *" << std::endl;
  26.     std::cout << second << std::endl;
  27.     std::cout << first << std::endl;
  28.    
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment