Comparing lines inside a vector<string>
<p>How do you read lines from a vector and compare their lengths? I have pushed strings inside a vector and now would like to find the longest line and use that as my output. I have this as my code all the way up to comparing the strings:</p>

<pre><code>ifstream code_File ("example.txt");

size_t  find_Stop1, find_Stop2, find_Stop3, find_Start;
string line;
vector&lt;string&gt; code_Assign, code_Stop;


if (code_File.is_open()) {
    while ( getline(code_File,line)) {



        find_Start = line.find("AUG");                        // Finding all posssible start codes
        if (find_Start != string::npos) {
            line = line.substr(find_Start);
            code_Assign.push_back(line);                            //adding line to Code_Assign


            find_Stop2 = line.find("UGA");                              //  Try and find stop code.
                if (find_Stop2 != string::npos) {

                    line = line.substr(line.find("AUG"), find_Stop2);
                    code_Stop.push_back(line);                          // Adding it to code_Stop vector
                                                }

           find_Stop1 = line.find("UAA");                               //   finding all possible stop codes.
                if (find_Stop1 != string::npos) {
                    line = line.substr(line.find("AUG"), find_Stop1);     // Assign string code_1 from start code to UGA
                    code_Stop.push_back(line);                          //Adding to code_Stop vector
                                                }


           find_Stop3 = line.find("UAG");                               //  finding all possible stop codes.
                if (find_Stop3 != string::npos) {
                    line = line.substr(line.find("AUG"), find_Stop3);
                    code_Stop.push_back(line);                          //Adding to code_Stop vector
                                                }


            }



    }

    cout &lt;&lt; '\n' &lt;&lt; "Codes to use: " &lt;&lt; endl;
        for (size_t i = 0; i &lt; code_Assign.size(); i++)
            cout &lt;&lt; code_Assign[i] &lt;&lt; endl;

    cout &lt;&lt; '\n' &lt;&lt; "Possible Reading Frames: " &lt;&lt; endl;
        for (size_t i = 0; i &lt; code_Stop.size(); i++)
            cout &lt;&lt; code_Stop[i] &lt;&lt; endl;

    cout &lt;&lt; endl;


    std::vector&lt;std::string&gt;::iterator longest = std::max_element(code_Stop.begin(), code_Stop.end, compare_length);

    std::string longest_line = *longest; // retrieve return value



    code_File.close();


}
else cout &lt;&lt; "Cannot open File.";
</code></pre>

<p>to try and clarify my current output is this all in the code_Stop vector:</p>

<blockquote>
  <p>Possible Reading Frames: </p>
  
  <p>AUG GGC CUC GAG ACC CGG GUU UAA AGU AGG </p>
  
  <p>AUG GGC CUC GAG ACC CGG GUU</p>
  
  <p>AUG AAA UUU GGG CCC AGA GCU CCG GGU AGC GCG UUA CAU</p>
</blockquote>

<p>and I would just like to get the longest line.</p>

<p>Note, I am just learning about vectors, so please be kind...I have been getting a lot of help from this board and really much appreciated.</p>

<p>Ed. I changed the code to show where I have put it and it is giving me "Program received signal: 'EXC_BAD_ACCESS'". What have I done?</p>
