Question: collectWord Using C++, create a function that receives a multi-line string, then looks at each line of the multi-line string and collects all non-blank characters

collectWord

Using C++, create a function that receives a multi-line string, then looks at each line of the multi-line string and collects all non-blank characters on lines that start with a particular string (also knowns as a pattern). The function should then return the ordered collection of characters found after the pattern in the multi-line string.

The function should be named collectWord. It should return a reference to a string it receives as an argument. The function should accept three strings by reference. The first string is the multiline string, the second is the pattern, and the third string is a container the return value will be placed. The returned value should be a reference to the 3rd argument.

Submit your source code function in a file named functions_collectWord.cpp

Example test code:

#include  int main() { // Creates a multi-line string string multiLine = R"(T: a A: T: p A: d A: o T: p T: T: l A: g T: e T: )"; string conduit{}, pattern{"T:"}; string* conduit_pointer = &conduit; collectWord(multiLine, pattern, conduit); // Check that the conduit now holds the string "apple" assert(conduit == "apple"); conduit += " "; pattern = "A:"; conduit = collectWord(multiLine, pattern, conduit); // Check that the conduit now holds the string "apple dog" assert(conduit == "apple dog"); // Check that the variable returned is the same variable that went in assert(conduit_pointer == &conduit); 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!