title: Logic error in menu and read functions to save and read to and from a file
body: <p>This program is supposed to call a read and write function from a menu, ask for inputs, save those inputs to a file then output the data to the screen. The menu works but I can only write to the file and save the data and exit. I cannot read or output what is saved to the file. Any help with this will be greatly appreciated. I should have three working functions, main(), writeData(), and readData().</p>
  
  <pre><code>#include &lt; iostream &gt;
  #include &lt; fstream &gt;
  #include &lt; string &gt;
      using namespace std;
  
  void menu(void);
  void writeData(void);
  void readData(void);
  const char FileName[] = "TestAddress.txt";
  string choice;
  
  int main()
  {
      menu();
      return 0;
  }
  void menu(void)
  {
      while (choice != "Q") {
          cout &lt;&lt; "What would you like to do?\nA. Read the existing data:\nB. Write new data to the list:\nQ.Quit\n";
          cin &gt;&gt; choice;
          if (choice == "A") {
              readData();
          }
          else if (choice == "B") {
              writeData();
          }
          else
              break;
  
      }
  }
  
  void writeData(void)
  {
      ofstream outFile("testAddress.txt");
      string name;
      string street;
      string city;
      string state;
      int zip;
      string cont = "y";
      ifstream inFile;
  
      while (cont != "q") {
          cout &lt;&lt; "Please enter the name:\n";
          getline(cin, name);
          cout &lt;&lt; "Please enter the street:\n";
          getline(cin, street);
          cout &lt;&lt; "Please enter the city:\n";
          getline(cin, city);
          cout &lt;&lt; "Please enter the state:\n";
          getline(cin, state);
          cout &lt;&lt; "Please enter the zip code:\n";
          cin &gt;&gt; zip;
          outFile &lt;&lt; name &lt;&lt; street &lt;&lt; "#" &lt;&lt; city &lt;&lt; state &lt;&lt; zip &lt;&lt; endl;
          cin.ignore();
          cout &lt;&lt; "Would you like to continue? Type q to quit:";
          getline(cin, cont);
          cin.ignore();
      }
      outFile.close();
  
      inFile.open("testAddress.txt");
      string fieldBuffer;
      if (inFile.is_open()) {
          while (inFile.eof()) {
              getline(inFile, fieldBuffer, ',');
              cout &lt;&lt; fieldBuffer;
              cout &lt;&lt; endl;
  
          }
      }
  }
  //use # sign for delimiter
  void readData(void)
  {
      ifstream inMyStream(FileName);
      if (inMyStream.is_open()) {
          string recBreaks = "";
          recBreaks.assign(20, '*');
  
          int fieldCount = 0;
          int recordCount = 1;
  
          fieldCount = 1;
          string fieldBuffer;
          getline(inMyStream, fieldBuffer, '#');
  
          while (inMyStream.eof()) {
              switch (fieldCount) {
                  case 1:
                      cout &lt;&lt; recBreaks &lt;&lt; endl;
                      cout &lt;&lt; "Record #" &lt;&lt; recordCount &lt;&lt; endl;
                      cout &lt;&lt; "Name...." &lt;&lt; fieldBuffer &lt;&lt; endl;
                      break;
                  case 2:
                      cout &lt;&lt; "Street...." &lt;&lt; fieldBuffer &lt;&lt; endl;
                      break;
                  case 3:
                      cout &lt;&lt; "City...." &lt;&lt; fieldBuffer &lt;&lt; endl;
                      break;
                  case 4:
                      cout &lt;&lt; "State...." &lt;&lt; endl;
                      break;
                  case 5:
                      cout &lt;&lt; "Zip Code...." &lt;&lt; endl;
                      fieldCount = 0;
                      recordCount++;
                      break;
                      getline(inMyStream, fieldBuffer, '#');
                      fieldCount++;
              }
              cout &lt;&lt; recBreaks &lt;&lt; endl;
              inMyStream.close();
  
  
          }
  
      }
  
  }
  </code></pre>