title: Search a sequence in a string. DNA
body: <p>I need to do a program that separate from 3 to the size of a string and compare to the others sequences of 3 in the same string given. I'm going to explain it.</p>
  
  <p>User introduce this DNA string  = "ACTGCGACGGTACGCTTCGACGTAG" For example.
  We start with n = 3, this is, we take the first three caracters for comparing in the DNA.</p>
  
  <p>The first characters are: "ACT", and we need to compare it with the other sequences of three, like, [CTG,TGC,GCA... until the end]. </p>
  
  <p>If we find another sequence equal to "ACT", we save the position.
  Here is another example:</p>
  
  <p>DNA: "ACTGCGACGGTACGCTTCGACGTAG" and we find this sequences in his positions:</p>
  
  <ol>
  <li>ACG: 7 - 12 - 20</li>
  <li>CGA: 5 - 18</li>
  <li>GAC: 6 - 19</li>
  <li>GTA: 10 - 22</li>
  <li>CGAC: 5 - 18</li>
  <li>GACG: 6 - 19</li>
  <li>CGACG: 5 - 18
  The number is the position of the start of the sequence:</li>
  </ol>
  
  <p>ACTGCG<strong>ACG</strong>GT<strong>ACG</strong>CTTCG<strong>ACG</strong>TAG</p>
  
  <p>You can see that the n = 3, increment in 1 when the we end to find by n = 3, the variable pass to n=4, until n = DNA.size().</p>
  
  <p>My problem is that i have one function for divide the string in a little sequences of the DNA, and I do a push_back() for saving in the vector, and then I can see if there is more sequences or not, but i don't know how can i get the position.</p>
  
  <p>I can use the library algorithm, and for sure, in this library there is a function that do this but i don't know so much this library.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  const string DNA = "ACTGCGACGGTACGCTTCGACGTAG";
  const size_t taille = DNA.size();
  
  size_t m = 3;
  vector&lt;string&gt; v;
  
  /*
  struct DNA{
      const string dna;  // chaine saisie pour l'utilisateur
      size_t taille;  // Taille de la chaine
      string chaine;  // Chaine à chercher
  };
  */
  
  // what kind of structs can i create? for me it's stupid to make any struct in this program.
  
  bool checkDNA(string &amp;s);
  string takeStrings(const string &amp;s,size_t i, size_t m);
  void FindSequenceDNA(vector&lt;string&gt;&amp;s,string sq);
  size_t incrementValue(size_t &amp;m);
  
  
  
  int main(){
  
      string DNAuser;
      cout &lt;&lt; "Introduce the DNA: ";
      cin &gt;&gt; DNAuser;
  
      bool request;
      cout &lt;&lt; boolalpha;
      request = DNAuser.find_first_not_of("AGCT");
      cout &lt;&lt; request &lt;&lt; endl;
  
      vector&lt;string&gt; vectorSq;
      size_t auxiliar = 0;
      string r;
      size_t ocurrencies = DNA.size()-2;
      cout &lt;&lt; "DNA: " &lt;&lt; DNA &lt;&lt; endl;
      while(auxiliar&lt;ocurrencies){        // This gonna be works with the ocurriences, from 1 to end.
          r = takeStrings(DNA,auxiliar,auxiliar+m);
          auxiliar++;
          if(r.size()==m){
              vectorSq.push_back(r);
          }
      }
  
      // string res = takeStrings(DNA,0,3);
      // cout &lt;&lt; "res: " &lt;&lt; res &lt;&lt; endl;
      // cout &lt;&lt; "Printing vector: " &lt;&lt; endl;
  
      // I just need to find the other, the practice is almost done.
  
      for(size_t i = 0; i&lt; vectorSq.size(); i++){
          cout &lt;&lt; vectorSq[i] &lt;&lt; endl;
      }
  
      return 0;
  
  }
  
  
  string takeStrings(const string &amp;s,size_t i, size_t m){
      string result;
      size_t aux=i;
      if(s.size()==0){
          cout &lt;&lt; "String is empty." &lt;&lt; endl;
      }
      else{
          for(;i&lt;s.size()&amp;&amp;i!=m;i++){
              result+=s[i];
              aux++;
          }
  
      }
      return result;
  }
  
  void FindSequenceDNA(vector&lt;string&gt;&amp;s,string sq){
      if(s.size()==0){
          cout &lt;&lt; "DNA invalid." &lt;&lt; endl;
      }
      else{
          for(size_t i=0;i&lt;s.size();i++){
              if(sq==s[i]){
                  cout &lt;&lt; "function: " &lt;&lt; endl;
                  cout &lt;&lt; s[i] &lt;&lt; endl; // I need to calculate the real position in the string, not in the vector
              }
          }
      }
  
  }
  
  bool checkDNA(string &amp;s){
      bool res;
      if(s.size()==0 || s.size()&lt;3){
          cout &lt;&lt; "DNA invalid" &lt;&lt; endl;
      }
      else{
          for(size_t i=0;i&lt;s.size();i++){
              if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T')
              {
                  res = true;
              }
              else{
                  res= false;
              }
          }
      }
      return res;
  }
  
  size_t incrementValue(size_t &amp;m){
      if(m&lt;DNA.size()){
          m++;
      }
      return m;
  }
  </code></pre>