Loading Issues

Ok guys I'm having a loading issue...
I'm making a Text Based RPG and i want people to have 2 worded names and or town names this will help with my loading item names too.

Declaring Player Name
1
2
3
cout << "Enter you characters Name: ";
cin.ignore(100,'\n');
getline (cin, Player.Name);

Say my Input was Steve Smith

Saving...
1
2
3
4
5
6
	ofstream myfile ((Player.ClassName)+".sav", ios::out);

	if(myfile.is_open())
	{
		myfile << Player.Name << "\n";
        }


Now inside of that saved file it would say

Steve Smith

Loading...
1
2
3
4
5
6
7
8
9
10
11
12
13
cout << "Enter the class you would like to load" << endl;
	
string Classname;
	
cin >> Classname;

ifstream myfile ((Classname)+".sav", ios::in);

if(myfile.is_open())
{
	myfile >> Player.Name;
        myfile >> Example;
}


Now when i want Steve Smith to be loaded to Player.Name it hits the whitespace and stops so Player.Name = Steve and Example = Smith and it messes up all the other variables in my game

I Apologize for any mess ups with the code first post.
You should use getline for your input instead.
http://www.cplusplus.com/reference/string/getline/
Last edited on
1
2
3
cout << "Enter you character's name: ";
cin.ignore(100,'\n');
getline (cin, Player.Name);


Didn't I?

Player.Name is a string for more detail
Last edited on
Topic archived. No new replies allowed.