A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Remove All Whitespace in C++ page! Here, you'll find the source code for this program as well as a description of how the program works.
#include <iostream>
#include <string>
#include <cctype> // for std::isspace
int main(int argc, char* argv[]) {
// Check if given string passed
if (argc < 2) {
std::cout << "Usage: please provide a string" << std::endl;
return 1; // Return error code if no string is given
}
// Get the string passed
std::string input = argv[1];
std::string result;
// Check if input string is empty
if (input.empty()) {
std::cout << "Usage: please provide a string" << std::endl;
return 1; // Exit error code if the string is empty
}
for(char c : input) {
// If the character is not a whitespace character, add it to result
if (!std::isspace(static_cast<unsigned char>(c))) {
result += c;
}
}
//print out the result (string should have no spaces)
std::cout << result << std::endl;
return 0;
}
Remove All Whitespace in C++ was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.