Quantcast
Channel: Remove extra white spaces in C++ - Stack Overflow
Browsing latest articles
Browse All 12 View Live

Answer by Hedgehog Mind for Remove extra white spaces in C++

I don't know if this helps but this is how I did it on my homework. The only case where it might break a bit is when there is spaces at the beginning of the string EX " wor ds " In that case, it will...

View Article



Answer by Galik for Remove extra white spaces in C++

You can use std::unique which reduces adjacent duplicates to a single instance according to how you define what makes two elements equal is.Here I have defined elements as equal if they are both...

View Article

Answer by Jan for Remove extra white spaces in C++

I ended up here for a slighly different problem. Since I don't know where else to put it, and I found out what was wrong, I share it here. Don't be cross with me, please.I had some strings that would...

View Article

Answer by Hans for Remove extra white spaces in C++

Well here is a longish(but easy) solution that does not use pointers.It can be optimized further but hey it works.#include <iostream>#include <string>using namespace std;void...

View Article

Answer by Peter - Reinstate Monica for Remove extra white spaces in C++

I have the sinking feeling that good ol' scanf will do (in fact, this is the C school equivalent to Anatoly's C++ solution):void remove_extra_whitespaces(char* input, char* output){ int srcOffs = 0,...

View Article


Answer by Christophe for Remove extra white spaces in C++

There are already plenty of nice solutions. I propose you an alternative based on a dedicated <algorithm> meant to avoid consecutive duplicates: unique_copy(): void remove_extra_whitespaces(const...

View Article

Answer by villapx for Remove extra white spaces in C++

Here's a simple, non-C++11 solution, using the same remove_extra_whitespace() signature as in the question:#include <cstdio>void remove_extra_whitespaces(char* input, char* output){ int...

View Article

Answer by Jts for Remove extra white spaces in C++

Since you are writing c-style, here's a way to do what you want.Note that you can remove '\r' and '\n' which are line breaks (but of course that's up to you if you consider those whitespaces or...

View Article


Answer by Lol4t0 for Remove extra white spaces in C++

for in-place modification you can apply erase-remove technic:#include <string>#include <iostream>#include <algorithm>#include <cctype>int main(){ std::string input {"asfa sas f...

View Article


Answer by anatolyg for Remove extra white spaces in C++

Since you use C++, you can take advantage of standard-library features designed for that sort of work. You could use std::string (instead of char[0x255]) and std::istringstream, which will replace most...

View Article

Answer by Ami Tavory for Remove extra white spaces in C++

There are plenty of ways of doing this (e.g., using regular expressions), but one way you could do this is using std::copy_if with a stateful functor remembering whether the last character was a...

View Article

Remove extra white spaces in C++

I tried to write a script that removes extra white spaces but I didn't manage to finish it. Basically I want to transform abc sssd g g sdg gg gf into abc sssd g g sdg gg gf.In languages like PHP or C#,...

View Article
Browsing latest articles
Browse All 12 View Live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>