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++?
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
}
+ 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
0
ok
0
thank you brother