0

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;

}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Ancient Dragon
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.