title: stop getline from discarding newline character
body: <p>if I have a text file like this :</p>
  
  <pre><code>this is line one
  This is line two
  this is line three
  </code></pre>
  
  <p>How would I use getline to read each into a stringstream, then print the stream into a new string while preserving the newline character? I am on a mac using Xcode 4. Here is my code: I am having trouble because the text it prints out only prints on one line. </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;sstream&gt;
  #include &lt;cctype&gt;
  using namespace std;
  string getInput ();
  ifstream * openInFile ();
  int getShiftValue ();
  void cypherMenu ();
  void menu ();
  string shiftCharacters (int shiftNum, ifstream * inFile);
  string getOutput ();
  ofstream * openOutFile ();
  void printSentence (string outData, ofstream * outFile);
  void notOption (string optionString);
  string capitalize (string choice);
  string option ();
  int main() {
  ifstream * inFile;
  ofstream * outFile;
  string inFileName, outFileName, outData, optionString, capOptionString; 
  int shiftNum = 0;
  bool isOption = false; 
  while (capOptionString.compare("2") != 0 || 
        capOptionString.compare("QUIT") != 0) {
     do {
     menu();
  
     optionString = option();
     capOptionString = capitalize(optionString);
     if (capOptionString.compare("1") == 0 || capOptionString.compare("CAESAR")
         == 0) {
         isOption = true;
     }
     else if (capOptionString.compare("2") == 0 || 
              capOptionString.compare("QUIT") == 0) {
         isOption = false;
         return 0;
     }
     else {
         notOption(optionString);
     }
     }
     while (!isOption);
     cypherMenu();
  
  
  
  
     inFile = openInFile(); 
     shiftNum = getShiftValue();
     outData = shiftCharacters(shiftNum, inFile);
     inFile-&gt;clear();
     inFile-&gt;close();
     outFile = openOutFile();
     printSentence(outData, outFile);
     outFile-&gt;clear();
     outFile-&gt;close();
  }
     return 0;
  }
  // Input Functions
  string getInput () {
  cout &lt;&lt; "Enter an input file name: "; 
  string inFileName;
  getline(cin, inFileName); 
  return inFileName;
  }
  string getOutput () {
  string outFileName;
  cout &lt;&lt; "Enter an output file name: ";
  getline(cin, outFileName);
  cout &lt;&lt; endl;
  return outFileName;
  }
  ifstream * openInFile () {
  ifstream * inFile;   
  bool isGood = false; 
  string inFileName;    
  inFile = new ifstream;
  do {   
      inFileName = getInput();
      inFile-&gt;open(inFileName.c_str());
     if (inFile-&gt;fail()) { 
         cout &lt;&lt; "Couldn't open file" &lt;&lt; endl;
      }
     else {
         isGood = true;
     }
  }
  while (!isGood);
  return inFile;
  }
  ofstream * openOutFile () {
  ifstream testStream; 
  ofstream * outFile;   
  bool isUnique = false; 
  string fileName;
  do {   
     fileName = getOutput();
     testStream.clear(); 
     testStream.open(fileName.c_str(), ios_base::in);
     if (testStream.good()) {
              cout &lt;&lt; "The file already exists, please choose another" 
              &lt;&lt; endl;
              testStream.clear();
              testStream.close();
      }
      else {
              isUnique = true;
              testStream.clear();
              testStream.close();
      }
  }
  while (!isUnique);
  outFile = new ofstream;
  outFile-&gt;open(fileName.c_str());
  return outFile;
  }
  int getShiftValue () {
  int shiftNum;
  string trash;
  cout &lt;&lt; "Please enter shift value: ";
  cin &gt;&gt; shiftNum;
  getline(cin, trash); 
  return shiftNum;
  }
  string option () {
  string optionString;
  getline(cin, optionString);
  cout &lt;&lt; endl;
  return optionString;
  }
  // Data manipulation functions 
   **string shiftCharacters (int shiftNum, ifstream * inFile){
   string inData, outData, trash; 
   char outChar;
  int idx = 0, length = 0;
  stringstream outSentence; 
   do { 
   while (getline(* inFile, inData, '\n')) {
       getline(* inFile, trash);
       for (idx = 0; idx &lt;= inData.length() - 1; idx++) {
          if (inData[idx] &gt;= 'a' &amp;&amp; inData[idx] &lt;= 'z') {
              outChar = (((inData[idx] - 'a') + shiftNum) % 26) +
              'a';
              outSentence &lt;&lt; outChar;
              length += 1;
          }
          else if (inData[idx] &gt;= 'A' &amp;&amp; inData[idx] &lt;= 'Z') {
              outChar = (((inData[idx] - 'A') + shiftNum) % 26) +
              'A';
              outSentence &lt;&lt; outChar;
              length += 1;
          }
  
  
          else {
              outChar = inData[idx];
              outSentence &lt;&lt; outChar;
              length += 1;
          }
      }
       outSentence &lt;&lt; trash;
  
   }
   }
   while (!(inFile-&gt;eof()));
  
  
   outData.resize(length);
  
  while (!(outSentence).eof()) {
      // outSentence &gt;&gt; noskipws &gt;&gt; outData;
       getline(outSentence, outData);
  
   }
  
   return outData;
   }**
  string capitalize (string choice) {
  string outString;
  outString.resize(choice.length());
  transform(choice.begin(), choice.end(), outString.begin(), ::toupper);
  return outString;
  }
  // Output funcitons
  void cypherMenu () {
  cout &lt;&lt; "C A E S A R  C Y P H E R  P R O G R A M" &lt;&lt; endl
      &lt;&lt; "========================================" &lt;&lt; endl;
  
  
    return;
      }
      void printSentence (string outData, ofstream * outFile) {
      int idx = 0;
      char outChar;
      stringstream outString;
      outString &lt;&lt; outData;
      for (idx = 0; idx &lt;= outData.length() - 1; idx++) {  
          outChar = outString.get();
          outFile-&gt;put(outChar); 
      }
      }
      void menu () {
      cout &lt;&lt;  "Available Options: " &lt;&lt; endl 
          &lt;&lt; "1. CAESAR - encrypt a file using Caesar Cypher" &lt;&lt; endl
          &lt;&lt; "2. QUIT - exit the program" &lt;&lt; endl &lt;&lt; endl
          &lt;&lt; "Enter a keyword or option index: ";
      return;
      }
      void notOption (string optionString) {
      cout &lt;&lt; optionString &lt;&lt; " is an unrecognized option, try again" &lt;&lt; endl 
          &lt;&lt; endl;
      return;
      }
  </code></pre>
  
  <p>The Problem lies within the function shiftCharacters. I am not sure how to get it to preserve the new line character please help?? The code is compilable.</p>