Hey guys I made this program that works fine but the thing is I have to add a feature that will ask the user if they have more records to add to the file. Keep adding records until the response is No. Thanks.

#include <iostream>
#include <fstream>

using namespace std;

int main(){

ofstream outputFile("TestbyCox.txt"); //ofstream will create the file if it doesn't exist, ifstream will not
ifstream inputFile;              // input file

char myString[100];              // length of the string

cout << "Enter a string: ";
cin.getline( myString, 100, '\n');

cout << "Writting string to file...\n";

outputFile << myString;

outputFile.close();

inputFile.open("TestbyCox.txt");

cout << "Reading string from file...\n";

inputFile.getline(myString, 100, '\n');


cout << myString;          // Displaying the file contents



system("pause");

return 0;

}

So what's the big problem? You might have to change the structure of the whole problem, such as make a menu such as

1. Add new string to file
2. Display file contents
3. Quite

Then create a switch statement that processes the requested action.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.