fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. //#include <windows.h>
  4. using namespace std;
  5.  
  6. string Center(string str) {
  7. int espacos = (int)((21 - str.length())/2);
  8. return string(espacos, ' ') + str + string(espacos + (str.length() > espacos * 2 ? 1 : 0), ' ');
  9. }
  10.  
  11. int main() {
  12. string mensagem;
  13. // HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
  14. cout << "Digite um palavara: ";
  15. cin >> mensagem;
  16. // SetConsoleTextAttribute( handle, 12 );
  17. cout << "***************************" "\n";
  18. cout << "***************************" "\n";
  19. cout << "*** ***" "\n";
  20. cout << "*** ***" "\n";
  21. cout<< "***" << Center(mensagem) << "***""\n";
  22. cout << "*** ***" "\n";
  23. cout << "*** ***" "\n";
  24. cout << "***************************" "\n";
  25. cout << "***************************" "\n";
  26. // SetConsoleTextAttribute( handle, 0 );
  27. return 0;
  28. }
  29.  
  30. //https://pt.stackoverflow.com/q/50496/101
Success #stdin #stdout 0s 15240KB
stdin
teste
stdout
Digite um palavara: ***************************
***************************
***                     ***
***                     ***
***        teste        ***
***                     ***
***                     ***
***************************
***************************