c++ string position find char code example
Example 1: how to check string contains char in c++
std::string s = "Hello";
if (s.find('e') != std::string::npos)
cout << "Found";
else
cout << "Not Found";
Example 2: find character in string c++
auto char_to_find = 'a'
if (str.find(char_to_find) != std::string::npos) {
}
Example 3: index string c++
#include <string>
#include <iostream>
int main(){
std::string string = "Hello, World!";
char stringindex = string[2];
}
Example 4: c++ length of char*
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char *str = "ABC";
cout << strlen(str) << endl;
return 0;
}
Example 5: find in string c++
size_t find (const string& str, size_t pos = 0) const;