0

IndexOf in c++

Hello guys , i already learn c# , and now i am learning c++ so i can see that they are very similiary.... But i have a problem ... I want to know what is the number of the char “x” in a string . For example C# String a = “hello”; Consolé.WriteLine( a.IndexOf(“h”) ); Output : 0... So .. how can i do the same but in c++?

12th Sep 2020, 6:23 PM
Wilkin Trinidad
Wilkin Trinidad - avatar
4 Respuestas
0
jayKrishna thank you this is the code str.find_first_of('a'); example: #include<iostream> using namespace std; int main() { string str = "javatpoint tutorial"; cout << "String contains :" << str<< '\n'; cout <<"Position of the first occurrence of 'a' character is :" << str.find_first_of('a'); return 0; please check the pagine }
12th Sep 2020, 7:28 PM
Wilkin Trinidad
Wilkin Trinidad - avatar
+ 1
In c++, s[i] return char at index i. Use a loop and compare with s[i] =='h' And also check string function in c++. There are function to check char is in string or not.. . Edit : Wilkin Trinidad check this.. https://www.javatpoint.com/cpp-string-find-first-of-function https://www.javatpoint.com/cpp-strings
12th Sep 2020, 7:07 PM
Jayakrishna 🇮🇳
0
ok
12th Sep 2020, 7:09 PM
Wilkin Trinidad
Wilkin Trinidad - avatar
0
thank you brother
12th Sep 2020, 7:24 PM
Wilkin Trinidad
Wilkin Trinidad - avatar