Useful C++ snippet. A better way to read in a sentence with STDIN.

Posted: September 24, 2011. At: 12:13 PM. This was 6 years ago. Post ID: 1988
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

Tsar Bomba on a car. A misfire?
Tsar Bomba on a car. A misfire?

This is a very useful C++ code snippet for reading in a line of text into STDIN. Hopefully this will be useful to someone.

#include <iostream>
#include <string.h>
#include <sstream>
using namespace std;
int goku(void) {
	cout << "Hello, Please enter your name.\n" << endl;
	return 1;
int main(int argc, char **argv) {
	string name = "";
	getline(cin, name);
	cout << "Welcome "<< name << ".\n"<< endl;
	return 0;

No comments have been made. Use this form to start the conversation :)

Leave a Reply