This is in C++. Write a function that, given a string, index, and character, returns the index of the first occurrence of the character starting the search at the index. If not found, return -1. If the inputs are "Hello-friends", 3, and 'e', the function returns 9 (indexing the 'e' in friends). Use a for loop along with a boolean variables to indicate the character was found, which should end the for loop immediately.   main.cpp #include #include using namespace std; // Type your code here int main() { string inputString; int startIndex; char searchChar; cin >> inputString; cin >> startIndex; cin >> searchChar; cout << FindNextCharInString(inputString, startIndex, searchChar) << endl; return 0; }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section9.3: The String Class
Problem 7E
icon
Related questions
Question

This is in C++.

Write a function that, given a string, index, and character, returns the index of the first occurrence of the character starting the search at the index. If not found, return -1. If the inputs are "Hello-friends", 3, and 'e', the function returns 9 (indexing the 'e' in friends). Use a for loop along with a boolean variables to indicate the character was found, which should end the for loop immediately.

 

main.cpp

#include <iostream>
#include <string>
using namespace std;

// Type your code here

int main() {
string inputString;
int startIndex;
char searchChar;

cin >> inputString;
cin >> startIndex;
cin >> searchChar;

cout << FindNextCharInString(inputString, startIndex, searchChar) << endl;

return 0;
}

 

Thank you

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr