How to find the characters that a string consists of in C++

1 Answer

0 votes
#include <iostream>
#include <string>
#include <set>

int main() {
    std::string str = "C++ is a general-purpose programming language";
    
    std::set<char> unique_chars(str.begin(), str.end());
    
    for (char ch : unique_chars) {
        std::cout << ch << " ";
    }
}

 
 
/*
run: 
 
  + - C a e g i l m n o p r s u 
 
*/

 



answered Nov 25, 2024 by avibootz

Related questions

1 answer 105 views
1 answer 118 views
1 answer 101 views
1 answer 106 views
1 answer 121 views
1 answer 103 views
...