Need command name or example

Hello,

random backround;
I recently started learning how to program, I've made a few small programs and I want to challenge myself, this is not supposed to be anything serious as much is it to test myself.

I want to create an application that'll give a sentence, and in response you give it your answer, and according to your answer , the program will alter;

For example;

outprint : "You find yourself in a room"
user types in : "look around" or "examine room"


TL;DR VERSION :
What command[and what #include] do I need for a user to type in full sentences such as "pick up X", "examine Y", in which the program will outprint according to your command[pick up, examine, walk into... etc]



That'll be really helpful, thanks!
-Visual studio 2012
-Win32 App program
Last edited on
You could use the getline() function to read lines of text instead of up to the first instance of whitespace.
http://www.cplusplus.com/reference/string/string/getline/
Thanks Zhuge! That was really helpful!

I have another small question ;

Assuming I have two options in my program - Pick up & Examine

I use the getline command

if ( input == "Pick up")
cout<< "something";
if (input == "Examine");
cout<< "something else";

However, if it's NEITHER "Pick up" or "Examine", how do I tell the the program to ask again? Is it possible to tell the program the follow :

else
return to the getline command

Look at this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>

int main ()
{
	std::string name;
	do 
	{
		std::cout << "Please, enter your full name: ";
		std::getline (std::cin,name);
		std::cout << "Hello, " << name << "!\n";
	}while(name != "John Doe" && name != "john doe");
  return 0;
}


I hope it helps.
Topic archived. No new replies allowed.