So far, we have seen how to output data to the console via the cout object. The Standard Library also provides a cin stream object to allow you to input values from the command line.
Create a C++ source file and add the following code:
#include "utils.h" #include "name.h" void print_name() { std::cout << "Your first name? "; std::string name; std::cin >> name; std::cout << name; }
Save this file as name.cpp.
The first include file is the precompiled header, which will include the two Standard Library headers <iostream> and <string>, so you can use types declared in those files. The first line of the function prints the string Your first name? on the console. Note that there is a space after the query, ...