How to check if string contains special characters in C++

1 Answer

0 votes
#include <iostream>

int main() {
    std::string s = "c c++ javascript python c# php";
        
    std::string abc = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890_ ";        
        
    if (s.find_first_not_of(abc) != std::string::npos) {
        std::cout << "yes";
    } else {
        std::cout << "no";
    }
 
    return 0;
}
 
 
 
 
 
/*
run:
 
yes
 
*/

 



answered Feb 14, 2022 by avibootz
edited Sep 4, 2023 by avibootz

Related questions

1 answer 153 views
1 answer 167 views
1 answer 157 views
1 answer 172 views
1 answer 137 views
1 answer 146 views
...