Getting input from the keyboard via the command line


#include <iostream>
#include <string>
#include <sstream>
using namespace std;
	
	string entered_string;
	float my_float=0;
	int my_int=0;

	//Get input
	cout << "Enter something: ";
	getline(cin, entered_string);

	//Convert and display it
	stringstream(entered_string) >> my_float;		//Will be 0 if invalid
	stringstream(entered_string) >> my_int;			//Will be 0 if invalid

	if (entered_string.compare("4") == 0)		//0=strings are the same
	{
		cout << "It matched!" << endl;
	}
  
	cout << "You entered: " << entered_string << ".  As a float: " << my_float << ".  As an int: " << my_int << endl;