Initializing pointers with strings - C++ Data Type

C++ examples for Data Type:char array

Description

Initializing pointers with strings

Demo Code

#include <iostream>

int main() {//from   w  w w.java 2s  .  c om
    const char* pstar1 {"Java"};
    const char* pstar2 {"Oracle"};
    const char* pstar3 {"Javascript"};
    const char* pstar4 {"CSS"};
    const char* pstar5 {"HTML"};
    const char* pstar6 {"C"};
    const char* pstar7 {"C++"};
    const char* pstar8 {"Python"};
    const char* pstr {"Your lucky star is "};
  int choice {};

  std::cout << "Pick a lucky star! Enter a number between 1 and 8: ";
  std::cin >> choice;

  switch (choice)
  {
  case 1:
    std::cout << pstr << pstar1 << std::endl;
    break;
  case 2:
    std::cout << pstr << pstar2 << std::endl;
    break;
  case 3:
    std::cout << pstr << pstar3 << std::endl;
    break;
  case 4:
    std::cout << pstr << pstar4 << std::endl;
    break;
  case 5:
    std::cout << pstr << pstar5 << std::endl;
    break;
  case 6:
    std::cout << pstr << pstar6 << std::endl;
    break;
  case 7:
    std::cout << pstr << pstar7 << std::endl;
    break;
  case 8:
    std::cout << pstr << pstar8 << std::endl;
    break;
  default:
    std::cout << "Sorry, you haven't got a lucky star." << std::endl;
  }
}

Result


Related Tutorials