File Creation Program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 2
Reputation: Baseball400 is an unknown quantity at this point 
Solved Threads: 0
Baseball400 Baseball400 is offline Offline
Newbie Poster

File Creation Program

 
0
  #1
Oct 26th, 2009
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.

  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main(){
  7.  
  8. ofstream outputFile("TestbyCox.txt"); //ofstream will create the file if it doesn't exist, ifstream will not
  9. ifstream inputFile; // input file
  10.  
  11. char myString[100]; // length of the string
  12.  
  13. cout << "Enter a string: ";
  14. cin.getline( myString, 100, '\n');
  15.  
  16. cout << "Writting string to file...\n";
  17.  
  18. outputFile << myString;
  19.  
  20. outputFile.close();
  21.  
  22. inputFile.open("TestbyCox.txt");
  23.  
  24. cout << "Reading string from file...\n";
  25.  
  26. inputFile.getline(myString, 100, '\n');
  27.  
  28.  
  29. cout << myString; // Displaying the file contents
  30.  
  31.  
  32.  
  33. system("pause");
  34.  
  35. return 0;
  36.  
  37. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,546
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1483
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning
 
-7
  #2
Oct 26th, 2009
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC