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:
#includeint 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started