Question: The task for this assignment (in C++ ) is: Read in a list of words (whitespace-separated std::string values) from std::cin (until EOF or an error)

The task for this assignment (in C++) is:

  1. Read in a list of words (whitespace-separated std::string values) from std::cin (until EOF or an error) and put each word in a (single!) std::vector.
  2. Use the std::find() algorithm to find the iterator, pos1, of the first instance of the word "begin".
  3. Use the std::find() algorithm to find the iterator, pos2, of the last instance of the word "end".
  4. Output all of the words in the words between pos1 and pos2 using std::copy. (*pos1, i.e., the word "begin", must not be output.) Each word output must be followed by a space character.

Tips

  • Reading in whitespace-separated words is easy: by default C++ will skip over whitespace when using operator >>. This means cin >> str; where str is a std::string variable, will read in whitespace-separated words. :-)
  • After calling std::find() the first time, check if pos1 != v.end() and if it is not, then ++pos1. This will move pos1 to one position after the "begin" position, or, do nothing if "begin" was not found!
  • std::copy's third argument can be ostream_iterator(cout, " ").

Sample Input Files

The task for this assignment (in C++) is: Read in a list

Sample Program Runs

of words (whitespace-separated std::string values) from std::cin (until EOF or an error)

1. 2. $ cat a2-inputl.dat bad output begin 3. 5. 6. 7. 8. quick brown fox jumped end bad output2 $ cat a2-input2.dat bad outputi begin 9. 10. 11. 12. 13. a 14. 15. 16. quick brown fox jumped okay output2 $ cat a2-input3.dat bad outputi 17. 18. 19. 20. a 21. 22. 23. 24. 25. quick brown fox jumped end bad output2 1. 2. $ g++-10.2.0 -std=c++20 -Wall - Wextra-Werror a 2-soln.cxx $ ./a.out

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!