Help On Simple .dat Utility

This is a discussion on Help On Simple .dat Utility within the C++ Programming forums, part of the General Programming Boards category; I wrote a very simple .dat utility that can read write and convert dat to a text text file. I ...

  1. #1
    Registered User Led4urhead123's Avatar
    Join Date
    Jul 2008
    Posts
    3

    Help On Simple .dat Utility

    I wrote a very simple .dat utility that can read write and convert dat to a text text file. I would like the user to be able to specify the where the file is instead of the way i wrote my code, where the file has to be named data.dat and saved to the directory the program is in. Anyone have any idea how to let the user specify the directory??? I don't have tremendous skills in c++ so...

    Here is my code so far:

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    int main () {
        int ans;
        int l = 1;
        
    
    	char String[50];
    	
    	main:
    
    	cout << "\nData Reader V1.0 -----------------------------------------------------\n";
    	cout << "1] Write Data To .dat File\n";
    	cout << "2] Read .dat Data\n";
    	cout << "3] Output Data To DatConversion.txt\n";
    	cout << "--------------------------Enter Selection-----------------------------\n";
    	cout << "                                ";
    	cin >>  ans;
    	
    
    	
    	if (ans == 1){
        cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    	ofstream outputFile("Dat.dat"); 
      	ifstream inputFile;
      	
    	
                  
        cout << "--------------------------Data Input---------------------------------\n";
        
        textinput:
     
     	cin.getline( String, 50, '\n');
    	
    
    	outputFile << String;
    	l = l + 1;
    	if (l == 10){
              
              outputFile.close();
    
    	      
              
              system("pause");
              
              cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
              
              goto main;
              
              }
    
    	goto textinput;
        }
        
        
        
        if (ans == 2){
                cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
                ifstream inputFile;
              inputFile.open("Data.dat");
    
    	      cout << "Reading string from Data.dat ...\n";
    
    	      inputFile.getline(String, 50, '\n');
    
              cout << String;
              
              cout<<"\n Press Any Key To Go Back.\n";
              
              system("pause");         
              
              inputFile.close();
              
              cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
              
              goto main;
              }
        //dat converter      
        if(ans == 3){
               
               cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
               
               //Reading Data
               
               ifstream inputFile;
               
               inputFile.open("Data.dat");
    
    	       cout << "Reading string from file...\n";
    
    	       inputFile.getline(String, 50, '\n');
    	       
    	       inputFile.close();
    	       
    	       //write to data to txt file
    	       
    	       ofstream outputFile("DatConversion.txt", ios::app);
    	       
    	       outputFile.open("DatConversion.txt");           
               
               cout<<"\nWriting...";
               
               outputFile << String;
               
               outputFile.close();
               
               cout<<"\n Press Any Key To Go Back.";
              
              system("pause");
              
              cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";         
              
              goto main;
              }
               
              
      
          return 0;
      
      
    }

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Make a string, or array of characters that the user inputs. Then put that where the ofstream("Dat.dat") is. Something like...

    Code:
    char filename[50];
    
    cout<<"File name: "; cin>>filename;
    
    ofstream outputfile(filename);
    Same goes for where ever else you used "Dat.dat", just put your variable there instead.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 10:48 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. Simple Compile Time Problem - HELP!
    By kamikazeecows in forum Windows Programming
    Replies: 2
    Last Post: 12-02-2001, 12:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21