Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,109 questions

40,780 answers

573 users

How to move all special characters to the end of a string in C++

1 Answer

0 votes
#include <iostream>

using namespace std;

string move_special_characters_to_end(string s) { 
    int len = s.length(); 
  
    string chars = "", pecial_characters = ""; 
    for (int i = 0; i < len; i++) { 
        char ch = s.at(i); 
        if (isalnum(ch) || ch == ' ') 
            chars += ch; 
        else
            pecial_characters += ch; 
    } 
    return chars + pecial_characters; 
} 
  
int main() 
{ 
    string s("c++£$vb.net&%java*() php <>/python 3.7.3"); 

    cout << move_special_characters_to_end(s);
    
    return 0; 
} 


/*
run:

cvbnetjava php python 373++£$.&%*()<>/..

*/

 





answered Aug 11, 2019 by avibootz

Related questions

1 answer 80 views
1 answer 127 views
2 answers 170 views
2 answers 156 views
...