#include#include using namespace std; void OutputList(vector items, bool endParagraph) { for(int item : items) { cout << item; if(endParagraph) { cout << endl; } else { cout << " "; } } } int main() { vector numbers{1, 2, 3, 4, 5}; bool paragraph = true; OutputList(numbers, paragraph); return 0; }
#includeIn this example, we define a function called "OutputList" that takes in a list of strings and a boolean value for "endParagraph". The function then loops through the list and outputs each string to the console. If "endParagraph" is true, each string will be printed on a new line. Otherwise, they will be printed on the same line separated by a comma and a space. We then call this function in our main function and pass in a list of strings and a boolean value of "false" to print the names on the same line separated by a comma and space. We determine the package library to be the standard C++ library.#include #include using namespace std; void OutputList(list
items, bool endParagraph) { for(string item : items) { cout << item; if(endParagraph) { cout << endl; } else { cout << ", "; } } } int main() { list names{"John", "Smith", "Sarah", "Lee"}; bool paragraph = false; OutputList(names, paragraph); return 0; }