title: Is there a CompareTo method in C++ similar to Java where you can use > < = operations on a data type
body: <p>I know that in java there is a compareTo method that you can write in a class that will compare two variables and return a value -1, 1, or 0 signifing greater than, less than, and equal to operations. Is there a way to do this in C++?</p>
  
  <p>Background:
  Im creating a modified string class in which it takes a string and an arraylist. I want to be able to compare the string in a traditional fashion where if its lower in the alphabet it will be less than, than higher it would be greater than. Than i just want the array list to be linked to the files to store pages in which the word was indexed on in a text file. Anyways the specifics do not matter since i already have the class written. I just need to create compareTo method that would be able to be used in the main of my cpp file or by other data type like various trees for instance. </p>
  
  <p>Ill write the code in java as i know how and maybe someone can help me with C++ Syntax (im required to write in c++ for this project unfortunatly, and i am new to C++)</p>
  
  <p>I will shorten the code to give the rough outline of what im doing than write the compareTo method as i know how in java</p>
  
  <pre><code>class name ModifiedString
  Has variables: word , arraylist pagelist
  Methods: 
  getWord (returns the word associated with the class, i.e its string)
  appendPageList (adds page numbers to the array list, this doesnt matter in this question)
  </code></pre>
  
  <p>Hers how i would do it in java</p>
  
  <pre><code>int compareTo(ModifiedString a){
    if(this.getWord() &gt; a.getWord())
        return 1;
    else if (this.word() &lt; a.getWord())
        return -1;
    else return 0;
  }
  </code></pre>
  
  <p>Then when &lt; , > , or == is used on a ModifiedWord than the operations would be valid.</p>