theredp,
Before I answer your question about messy output caused by your std::cin, I will say this first.
I personally do not agree with your design decision.
OOP is all about modeling real world objects. I do not believe that it is CourseCatalog's responsibility to output message to the screen to get user responses and then add the course to its collection.
Let's talk about the Course Catalog in the real world.
1. It contains 1 or more courses (Hence, you have subjects map variable.)
2. You can add more courses to the catalog and remove old courses from the catalog (Hence, you have addCourse() and removeCourse() functions).
3. You can get course information from the catalog (Hence, you have getCourse() function)
So, all of these operations are consistent with what the course catalog actually does in the real world.
1 2 3 4 5 6 7 8
|
class CourseCatalog
{
map<string, string> subjects;
public:
void addCourse();
void getCourse();
void removeCourse();
};
|
What does your CourseCatalog have to do with actually getting input from user and add a course to itself? That's not consistent with what the course catalog is all about in the real world.
If anything, your main function or an utility function would have to get the user input and call addCourse() on CourseCatalog to add each course to the catalog.
If we go with the MVC model, View is the entity responsible for displaying information to user and getting input, controller would invoke an operation of Model to change the model's state, and model is the object class that maintains data state.
But anyways, I apologize for a long text that doesn't answer your question. Let's get back to your problem with std::cin.
When std::cin is used for a string variable, it will only extract a word (Up to any whitespace - including spaces, tab, newline) and store it in the string variable. In order to capture everything in a line including characters and spaces, you may want to use std::getline() function.
http://www.cplusplus.com/reference/string/string/getline/