A reading club needs a report with a full book title and a member label. This final text program combines safe in-memory input with a small string-returning helper.
The extraction operator >> reads a word into a string. For a title containing spaces, use std::getline(stream, destination). It reads characters up to a newline, stores them in the destination string, and consumes the newline without adding it to the string. Like extraction, it can be used in an if condition to check whether reading succeeded.
#include <iostream>
#include <sstream>
#include <string>
int main() {
std::istringstream source("Evening Walks\n");
std::string title = "";
if (std::getline(source, title)) {
std::cout << "Title: " << title << '\n';
}
return 0;
}
This fresh stream starts at the beginning of the title. When mixing >> and getline on the same stream, a newline left by formatted extraction needs separate handling. We avoid that complication here by giving getline its own prefilled stream.
The second part is a helper named memberLabel. A function can return std::string just as an earlier helper returned int. Its two string parameters hold copies of the supplied names. Join them with one space and return the new string; the existing caller handles output.
The title-reading task is in main; the name-joining task is in the helper above it. Work on the title first and check that all three words appear on the Book line. Then finish memberLabel and check the space between the names. The caller already prints the returned label, so the helper itself should not print another line.
false with std::getline(source, title) to read and check the full title. Expect Book: The Quiet Orchard.memberLabel return its two parameters joined with one space. Expect Member: Lena Ortiz.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.