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.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Next Steps:
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Apply for Computer Science Internship
- Apply for Information Technology Internship
- Practice Computer Science MCQs
- Buy Computer Science Books
- Practice Programming MCQs