Thursday, March 11, 2021

First and Last Character in a String in C++

 A program that I wrote using C++ to ask the user to give a string and then the program will identify which is the first and last character.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.







Program Listing

// string.cpp
// Mr. Jake R. Pomperada, MAED-IT, MIT
// www.jakerpomperada.com
// www.jakerpomperada.blogspot.com
// jakerpomperada@gmail.com
// Bacolod City, Negros Occidental Philippines

#include <iostream>
#include <string>

int main()
{
  std::string input;
  std::cout << "\n\n";
  std::cout << "\tFirst and Last Character in a String in C++";
  std::cout << "\n\n";
  std::cout << "\tEnter a string : ";
  std:: getline (std::cin, input);
  std::cout << "\n\n";
  if(!input.empty())
  std::cout << "\tThe first character is: " << input.front()
   << " the last character is: "
<< input.back() << "\n";
  else
    std::cout << "\tYou didn't enter anything.";
  std::cout << "\n\n";
  std::cout << "\tEnd of Program";
  std::cout << "\n\n";
}

No comments:

Post a Comment