Closing everytime I input a name/letter

so I'm busy making a simple text adventure game and right now i'm doing the
intro bit but everytime you insert a name my program just closes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  #include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	int awnser;
	int name;



	cout << "   Pugs in the world   " << endl;
	cout << "  By ShinyPug Company         " << endl;
	cout << "" << endl;
	cout << "" << endl;
	cout << "" << endl;
	cout << "" << endl;

	cout << "Owner: I'm going to call you..." << endl;
	cout << "Please enter a name." << endl;
	cin >> name;
	cout << "Owner: I'm going to call you " << name <<  endl;

	
	cin.ignore();
	cin.ignore();
	return 0;

}
I already know that but cin.ignore() normally works.
You have declared variable "name" as type int, you may want to change that to string. [you will need #include <stream>]

If you want user to be able to enter first and last name then use getline () instead of cin.

You also have typo in one of your variable names. It should be "answer" not "awnser".
RabMac String is under #include <string> not stream.
Well thanks for the info on the string part

but its still closing!
Use cin.get()
Yeah I meant <string> gibilit ;)

Instead of using cin use getline ()
@RabMac

getline ()

is not working

"getline is undefined"
std::getline( std::cin , string_goes_here );
that did not work but I figured something out!

when it closing I can only see a not amy
so I typed in a and that worked

but when I type in a full name it just closes.
Topic archived. No new replies allowed.