title: Sorting names between a Student class
body: <p>edit. I want to thank the two people who helped me in my code. I fixed my coding as of 7:22 PM PST 9/25/2014. Still having trouble with the sorting though.</p>
  
  <p>So I'm trying to teach myself how to use C++ in order to get ahead of my programming class in school. I've already taken Java so I'm relatively familiar with the structure of the coding but not exactly sure what to be typing. This practice problem is:</p>
  
  <p>1)Ask the user how many people he wants to enter into the list.</p>
  
  <p>2)Read 3 strings, then turn that info into a student class and put the student inside a vector.</p>
  
  <p>3)Sort the list by name. (Extra credit would be to sort the list by Student ID)</p>
  
  <p>4)Print the info of each student in the list.</p>
  
  <p>5)Ask user while answer is 'Y', search the list for a name and print the info correlating to the name</p>
  
  <p>While in Java, this seems pretty easy, I'm having an extremely hard time understanding what is going on in C++. </p>
  
  <p>I currently only have 1, 2, 4 and 5 done. This is what I have so far.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  #include &lt;sstream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  class Student
  {
      string myName, myStudentID, myClassID;
  public:
      Student(string name, string studentID, string classID)
      {
          myName = name;
          myStudentID = studentID;
          myClassID = classID;
      }
  
      string getName() { return myName; }
      string getStudentID() { return myStudentID; }
      void printInfo() { cout &lt;&lt; myName &lt;&lt; setw(15) &lt;&lt; myStudentID &lt;&lt; setw(10) &lt;&lt; myClassID &lt;&lt; endl; }
  
  
  
  };
  
  int main()
  {
      int num;
      std::vector&lt;Student&gt; studentList;
      cout &lt;&lt; "How many students do you wish to add to the student list ? " &lt;&lt; endl;
      cin &gt;&gt; num;
  
  
      cin.ignore();
      for (int a = 0; a &lt; num; a++)
      {
  
          string inputName, inputStudentID, inputClassID;
          //get name
          cout &lt;&lt; "Please enter the Student name : ";
          getline(cin, inputName);
  
  
          //get student ID
          cout &lt;&lt; "Please enter the Student ID number : ";
          getline(cin, inputStudentID);
  
  
          //get class ID
          cout &lt;&lt; "Please enter the Student class ID : ";
          getline(cin, inputClassID);
  
  
  
          Student thisStudent(inputName, inputStudentID, inputClassID);
          studentList.push_back(thisStudent);
  
          cout &lt;&lt; endl;
      }
  
      //sort(studentList.begin(), studentList.end());
      /*
      I never figured out how to sort the list by name.
      I do not know how to compare the name of studentList[0] and studentList[1]
      to put them in alphabetical order.
      */
      cout &lt;&lt; endl;; // FORMATTING
  
      cout &lt;&lt; "The student list has a size of " &lt;&lt; studentList.size() &lt;&lt; endl;
  
      cout &lt;&lt; endl;; // FORMATTING
  
  
      cout &lt;&lt; "Student Name" &lt;&lt; setw(15) &lt;&lt; "Student ID" &lt;&lt; setw(10) &lt;&lt; "Class ID" &lt;&lt; endl;
      for (int a = 0; a &lt; studentList.size(); a++)
      {
          studentList[a].printInfo();
      }
  
      cout &lt;&lt; endl;; // FORMATTING
  
  
      string searchedName;
      char answer;
      do
      {
          cout &lt;&lt; endl;; // FORMATTING
          cout &lt;&lt; "Please type the name of the person you want to search for: ";
          getline(cin, searchedName);
          for (int a = 0; a &lt; studentList.size(); a++)
          {
              if (searchedName.compare(studentList[a].getName()) == 0)
              {
                  studentList[a].printInfo();
                  break;
              }
              else
                  if (a == (studentList.size() - 1)) //If went to end of the list, tell them name not found.
                      cout &lt;&lt; "There is no " &lt;&lt; searchedName &lt;&lt; " in the list. \n";
  
  
          }
  
          cout &lt;&lt; "Would you like to search for another person? \n";
          cout &lt;&lt; "Y for Yes, N for No. \n";
          cin &gt;&gt; answer;
          cin.ignore();
  
      } while (answer == 'Y' || answer == 'y');
  
  
      return 0;
  
  
  
  
  }
  </code></pre>