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

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