title: How do I read a string from a text file and stop at a certain character? C++
body: <p>I'm decrypting an encrypted file that was made with my encryption program.  I'll try and explain the whole scenario so everyone gets what exactly my program is doing.</p>
  
  <p>My encryption program had the user input a string and then shifted the characters to the right by a random number between 8 and 15.  It then sent the encrypted file to a destination called secret.dat</p>
  
  <p>What it read in the encrypted file was</p>
  
  <pre><code>10rovvys1237123&amp;5#10
  </code></pre>
  
  <p>It tells you first what number the characters were shifted over as (10), then the encrypted string (hello 123 123), and the spaces used the character prior to the space and shited that character over by 4 (the 'y' and the '7'), and the '&amp;' character shows when the encryption is terminated.  After the '&amp;' character there are numbers seperated by the '#' character showing where the spaces are located.</p>
  
  <p>So first with the decryption program I used ifstream to open the file and read an integer to use as my shift to the left to encrypt it and then is where I run into the problem.  I can't figure out how to read the characters into a string up to the '&amp;' character so that I can shift those characters back to normal.  I found one way to get them but I can't figure out how to put them into a string.  </p>
  
  <p>This is what I did that I was able to grab the characters up to the '&amp;' character:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main()
  {
      //Declare Variables
      int shift;
      char character;
      char endOfFile = '&amp;';
      ifstream inData;
  
      //Open file
      inData.open("secret.dat");
  
      //Begin program
      inData &gt;&gt; shift;
      cout &lt;&lt; shift &lt;&lt; endl;
  
      inData.get(character);
  
      while(character != endOfFile)
      {
          if (character &gt;= 'a' &amp;&amp; character &lt;= 'z')
          {
              character = ((character - 'a' - shift) % 26) + 'a';
          }
          if (character &gt;= '0' &amp;&amp; character &lt;= '9')
          {
              character = ((character - '0' - shift) &amp; 10) + '0';
          }
          cout &lt;&lt; character;
          inData.get(character);
      }
      return 0;
  }
  </code></pre>
  
  <p>My second problem is my formula that I'm using to shift the characters back as it doesn't seem to work properly as I figured all I needed to do was change my encrypt formula that just added shift to subtracting shift.  But that's a different problem, main problem is grabbing the characters and putting them into a string so that I can use them later.  Right now the loop is just grabbing each character and putting it out but I can't access the characters besides the first one outside of the loop.</p>
  
  <p>Any help would be greatly appreciated as I can't seem to find my solution anywhere else.</p>