Write code in C++ to do the following: Ask a user to enter astring (consider space or any special characters). If the userenters ‘n’ clear the string and allow the user to enter anotherstring. If the user enters ‘.’ after a string (may or may not bespace included before ‘.’) then scan the staring including up to’.’ and print the scanned string.
Solution
#include<iostream>
using namespace std;
int main()
{
string str =“”;
// infinite loop
while(1)
{
cout<<“Enter a string :”;
// read a line
getline(cin,str);
// if user entersn
if(str.length() ==0 )
{
str = “”;
continue;
}
// store the stringupto ‘.’
string temp= “”;
inti;
// traverse