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

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

How to remove vowels from a string in C++

4 Answers

0 votes
#include <iostream>
#include <regex>

std::string remove_vowels(std::string s) { 
    std::stringstream result;
    std::regex vowels("[aeiouAEIOU]");
     
    regex_replace(std::ostream_iterator<char>(result), s.begin(), s.end(), vowels, "");
     
    return result.str();
}  
   
int main() 
{ 
    std::string str = "C++ PHP Java Python VB.NET Rust";  
 
    std::cout << remove_vowels(str); 
} 
 
 
 
 
 
/*
run:
 
C++ PHP Jv Pythn VB.NT Rst
 
*/

 



answered Aug 18, 2019 by avibootz
edited Nov 21, 2022 by avibootz
0 votes
#include <iostream>
#include <regex>

std::string remove_vowels(std::string s) { 
    std::regex vowels("[aeiouAEIOU]");

    return regex_replace(s, vowels, "");
}  
   
int main() 
{ 
    std::string str = "C++ PHP Java Python VB.NET Rust";  
 
    std::cout << remove_vowels(str); 
} 
 
 
 
 
 
/*
run:
 
C++ PHP Jv Pythn VB.NT Rst
 
*/

 



answered Nov 21, 2022 by avibootz
0 votes
#include <iostream>
 
int main()
{
    char str[] = "C++ PHP Java Python VB.NET Rust";
  
    int j = 0;
    for (int i = 0; i < str[i]; i++) {
        if (str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' && str[i] != 'u' &&
            str[i] != 'A' && str[i] != 'E' && str[i] != 'I' && str[i] != 'O' && str[i] != 'U') {
            str[j] = str[i];
            j++;
        }
    }
  
    str[j] = '\0';
  
    std::cout << str;
}
  
  
  
  
/*
run:
  
C++ PHP Jv Pythn VB.NT Rst
  
*/

 



answered Dec 26, 2023 by avibootz
0 votes
#include <iostream>
#include <vector>
#include <algorithm>
 
std::string RemoveVowels(std::string str) {
    std::vector<char> vowels = {'a', 'e', 'i', 'o', 'u',
                                'A', 'E', 'I', 'O', 'U'};
      
    for (int i = 0; i < str.length(); i++) {
        if (find(vowels.begin(), vowels.end(), str[i]) != vowels.end()) {
            str = str.replace(i, 1, "");
            i -= 1;
        }
    }
     
    return str;
}
 
 
int main()
{
    std::string str = "C++ PHP Java Python VB.NET Rust";
     
    str = RemoveVowels(str);
     
    std::cout << str;
}
  
  
  
  
  
/*
run:
  
C++ PHP Jv Pythn VB.NT Rst
  
*/
 

 



answered Dec 26, 2023 by avibootz

Related questions

1 answer 104 views
104 views asked Mar 27, 2022 by avibootz
1 answer 95 views
1 answer 111 views
111 views asked Nov 21, 2022 by avibootz
1 answer 111 views
111 views asked Nov 21, 2022 by avibootz
1 answer 105 views
1 answer 127 views
1 answer 93 views
...