Write a program that removes all spaces from the given input.Ex: If the input is:Hello my name is John.the output is:HellomynameisJohn.Your program must define and call the following function. The function should return a string representing the input string without spaces.string RemoveSpaces(string userString)#include <iostream>#include <algorithm>using namespace std;string removeSpaces(string str) { str.erase(remove(str.begin(), str.end(), ' '), str.end()); return str; }/* Define your function here */int main() {string str; str = removeSpaces(str); cout << str << endl; /* Type your code here. Your code must call the function. */return 0;}Please help me with this problem using c++.

Question
Asked Nov 21, 2019
156 views

Write a program that removes all spaces from the given input.

Ex: If the input is:

Hello my name is John.

the output is:

HellomynameisJohn.

Your program must define and call the following function. The function should return a string representing the input string without spaces.
string RemoveSpaces(string userString)

#include <iostream>
#include <algorithm>
using namespace std;

string removeSpaces(string str)
{
str.erase(remove(str.begin(), str.end(), ' '), str.end());
return str;
}


/* Define your function here */

int main() {
string str;
str = removeSpaces(str);
cout << str << endl;

/* Type your code here. Your code must call the function. */

return 0;
}

Please help me with this problem using c++.

check_circle

Expert Answer

Step 1

Program Instructions:

  • Ask the user to enter string on the screen, and take that input in ‘str’ variable of string type.
  • With the help of ‘getline()’ method of ‘string.h’ library takes the user’s input by passing ‘cin&rsq...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: Write down a Unix command that will change security permissions on a file named file1.txt so that th...

A: Ownership of filesUser (u): A person who creates the file. User is also known as owner of the file.G...

question_answer

Q: Identify, list, and define the six components of an information system.

A: Information System (IS):Information system is the system that deals with the organisation, storage, ...

question_answer

Q: To increase security of data stored on an RODC, what can be configured to specify domain objects tha...

A: Windows Server 2008 produces a new kind of domain controller, RODC (Read-only domain controller). Th...

question_answer

Q: Write three statements to print the first three elements of vector runTimes. Follow each with a newl...

A: A vector called runTime has to store 5 elements. This program prompts the user to enter the 5 elemen...

question_answer

Q: The area of an arbitrary triangle can be computed using the formulaarea = √(s(s–a)(s–b)(s–c))where t...

A: The C++ program will obey the following rubrics:Importing essential header files.Declaring integer d...

question_answer

Q: 1.Write a program in C++ , to count the number of people in each of the following age groups: 0-16 (...

A: Following is the approach of the program to count the number of persons of different age groups:Decl...

question_answer

Q: Write Python programs to solve the problem. Shipping is free for online orders totaling $50 or more ...

A: Python program that prompts for the unit price of an item and its quantity#get the inputs from the u...

question_answer

Q: List and define the factors that are likely to shift in an orginizations information security enviro...

A: Information security and its need:In essence, information security is the application of organizatio...

question_answer

Q: IN PYTHON Linked Lists Consider the implementation of the Linked list class, implement the following...

A: A Python program for the given scenarios is as follows,import random# Node class class Node:    # Co...