Answers for "c++ find string in string"

C++
4

c++ string contains

if (string1.find(string2) != std::string::npos) {
    std::cout << "found!" << '\n';
}
Posted by: Guest on April-02-2020
1

how to find something in a string in c++

const char* c = "Word";
string str = "WhereIsMyWordThatINeed";
cout << "the word is at index " << str.find(c);
//this will print "the word is at index 9"
Posted by: Guest on July-06-2021
-1

c++ find string in string

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>

int main()
{
    std::string in = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,"
                     " sed do eiusmod tempor incididunt ut labore et dolore magna aliqua";
    std::string needle = "pisci";
    auto it = std::search(in.begin(), in.end(),
                   std::boyer_moore_searcher(
                       needle.begin(), needle.end()));
    if(it != in.end())
        std::cout << "The string " << needle << " found at offset "
                  << it - in.begin() << '\n';
    else
        std::cout << "The string " << needle << " not found\n";
}
Posted by: Guest on August-21-2020
-2

string.find in c++

If not found then returns npos or -1 in int
Posted by: Guest on August-05-2021

Browse Popular Code Answers by Language