title: How to extract specific substring from getline function in C++?
body: <p>I'm fairly new to C++ so please forgive me if my terminology or methodology isn't correct. </p>
  
  <p>I'm trying to write a simple program that:</p>
  
  <ol>
  <li>Opens two input files ("infileicd" and "infilesel").<br></li>
  <li>Opens a single output file "list.txt". <br></li>
  <li>Compares "infilesel" to "infileicd" line by line.<br></li>
  <li>If a line from "infilesel" is found in "infileicd", it writes that line from "infileicd" to "list.txt", effectively making a separate log file. <br></li>
  </ol>
  
  <p>I am using the getline() function to do this but have run into trouble when trying to compare each file line. I think it might be easier if I could use only the substring of interest to use as a comparison.
  The problem is that there are multiple words within the entire getline string and I am only really interested in the second one. Here are two examples:</p>
  
  <p>"1529   nic1_mau_op_mode_3                  "8664afm007-01" "1" OUTPUT  1 0 LOGICAL 4   4136"</p>
  
  <p>"1523   pilot_mfd_only_sel                  "8664afm003-02" "1" OUTPUT  1 0 LOGICAL 4   4112"</p>
  
  <p>"nic1_mau_op_mode_3" and "pilot_mfd_only_sel" are the only substrings of interest.</p>
  
  <p>It would make it a lot easier if I could only use that second substring to compare but I don't know how to extract it specifically from the getline() function. I haven't found anything suggesting it is impossible to do this, but if it is impossible, what would be an alternative method for extracting that substring? </p>
  
  <p>This is a personal project so I'm under no time contstraints.</p>
  
  <p>Any assistance is greatly apprecated in advance. Here is my code (so far):</p>
  
  <pre><code>int main()
  {
      //Open the file to write the selected variables to.
      ofstream writer("list.txt");
  
      //Open the selected variabels file to be read.
      ifstream infilesel;
      infilesel.open("varsel.txt");
  
      //Open the icd file to be read.
      ifstream infileicd;
      infileicd.open("aic_fdk_host.txt");
  
      //Check icd file for errors.
      if (infileicd.fail()){
          cerr &lt;&lt; "Error opening icd.\n" &lt;&lt; endl;
          return 1;
      }
      else {
          cout &lt;&lt; "The icd file has been opened.\n";
      }
  
      //Check selected variables file for errors.
      if (infilesel.fail()){
          cerr &lt;&lt; "Error opening selection file.\n" &lt;&lt; endl;
          return 1;
      }
      else {
          cout &lt;&lt; "The selection file has been opened.\n";
      }
  
      //Read each infile and copy contents of icd file to the list file.
  
      string namesel;
      string nameicd;
  
      while(!infileicd.eof()){ 
  
          getline(infileicd, nameicd);
          getline(infilesel, namesel);
  
          if (nameicd != namesel){ //This is where I would like to extract and compare the two specific strings
              infileicd; //Skip to next line if not the same
  
          } else {
                  writer &lt;&lt; nameicd &lt;&lt; namesel &lt;&lt; endl;
          } 
      }
  
  
      writer.close();
      infilesel.close();
      infileicd.close();
  
      return 0;
  }
  </code></pre>
  
  <p></p>