- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ Program to remove spaces from a string?
The program takes a string and removes the spaces in it. This is useful when we want to save the space of our The following sample shows how it is done with an explanation.
Input: Hello World Output: HelloWorld
Explanation
To remove or delete spaces from the string or sentence, you have to ask the user to enter a string. Now start checking for spaces. If space will be found, then start placing the next character from the space to the back until the last character and continue to check for the next space to remove all the spaces present in the string
Example
#include <iostream> #include<string.h> using namespace std; int { char str[80]="Hello World"; int i=0, len, j; len = strlen(str); for( i = 0; i < len; i++) { if (str[i] == ' ') { for (j = i; j < len; j++) str[j] = str[j+1]; len--; } } cout << str; return 0; }
- Related Articles
- C++ program to remove spaces from a string using String stream
- Java Program to remove all white spaces from a String.
- Remove spaces from std::string in C++
- C program to remove extra spaces using string concepts.
- Java program to remove all the white spaces from a given string
- C program to remove spaces in a sentence using string concepts.
- How to remove double or more spaces from a string in MySQL?
- C# Program to split a string on spaces
- Trim (Remove leading and trailing spaces) a string in C#
- C# Program to remove duplicate characters from String
- C# program to remove n-th character from a string
- How to remove all special characters, punctuation and spaces from a string in Python?
- Remove extra spaces in string JavaScript?
- How to remove white spaces (leading and trailing) from string value in MongoDB?
- C# program to replace all spaces in a string with ‘%20’

Advertisements