This C++ Program which prints the name of the user using streams. The program asks user to input his/her name using Input Streams, the name is saved in a string variable and is printed using Output Stream.
Here is source code of the C++ program which prints the name of the user using streams. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Print the Name of the User using Output Stream
*/
#include <iostream>
#include <string>
int main()
{
std::string firstname;
std::cout << "Hello User, Enter your first name.\n ";
std::cin >> firstname;
std::cout << "Hello " << firstname
<<". It was nice to know your name!\n";
}
$ g++ main.cpp $ ./a.out Hello User, Enter your first name. George Hello George. It was nice to know your name!
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Check Computer Science Books
- Practice Computer Science MCQs
- Check Programming Books
- Check C++ Books
- Apply for C++ Internship