Still can not write or read from save file

This is a discussion on Still can not write or read from save file within the C++ Programming forums, part of the General Programming Boards category; I am pulling my hair out. Can someone please help I am lost with this. This is the code I ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    56

    Post Still can not write or read from save file!!PLEASE HELP

    I am pulling my hair out. Can someone please help I am lost with this. This is the code I am useing to save the file.

    [CODE]

    #include<iostream>
    #include<iomanip>
    #include<string>
    #include<cstdlib>
    #include<ctime>
    #include<fstream>
    #include<algorithm>
    int getpin(int & );
    int i;



    using namespace std;

    int main()
    {

    //declare variables

    string clerkId ="";
    int ssn =0;
    string name ="";
    string address ="";
    string city ="";
    string state ="";
    int zip =0;
    int pin = 0;
    int visa = 0;

    //enter input itesm to a file

    ofstream outfile;
    outfile.open("WACKOFILE.dat", ios:ut);

    if(outfile.is_open())
    {

    //Clerk is to enter ID for login Information

    cout<<"Enter ClerkId: ";
    getline(cin, clerkId);

    //This will Loop Through Program and then Exit Loop
    //Once Clerk-ID id Null

    while(clerkId != "xx")
    {

    //Get Name Address City State Zip Social Security Number


    cout <<"Enter SSN: ";
    cin>>ssn;
    cin.ignore(1);
    cout <<"Enter Name: ";
    getline(cin, name);
    cout <<"Enter Address: ";
    getline(cin, address);
    cout <<"Enter City: ";
    getline(cin, city);
    cout <<"Enter State: ";
    getline(cin, state);
    cout <<"Enter Zip: ";
    cin>>zip;
    pin = getpin(visa);
    cin.ignore(1);
    cin.ignore(1);

    // Format Title Lines for Name, Address, City, State, and Zip

    cout<<setw(25)<<left<<"Name"<<" "<<setw(25)<<left<<"Address"<<" "
    <<setw(16)<<left<<"City"<<" "<<setw(2)<<"ST"<<" "<<setw(5)<<left<<"Zip"<<endl;


    //Format Display Output

    cout<<setw(25)<<left<<name<<" "<<setw(25)<<left<<address<<" "
    <<setw(16)<<left<<city<<" "<<setw(2)<<state<<" "<<setw(5)<<setfill('0')<<right<<zip<<endl;
    cout<<setw(2)<<left<<"ClerkID"<<" "<<setw(9)<<setfill(' ')<<left<<"SSN"<<endl;
    cout<<setw(2)<<left<<clerkId<<" "<<setw(9)<<left<<ssn<<endl;

    outfile<<setw(25)<<left<<name<<" "<<setw(25)<<left<<address<<" "
    <<setw(16)<<left<<city<<" "<<setw(2)<<state<<" "<<setw(5)<<setfill('0')<<right<<zip<<endl;
    outfile<<setw(2)<<left<<"ClerkID"<<" "<<setw(9)<<setfill(' ')<<left<<"SSN"<<endl;
    outfile<<setw(2)<<left<<clerkId<<" "<<setw(9)<<left<<ssn<<endl;


    cout<<"Enter ClerkId: ";
    getline(cin, clerkId);


    }
    }
    else
    {cout<<"File not Open"<<endl;}
    outfile.close();
    return 0;

    }

    int getpin(int & visa)

    {



    srand(time(NULL));

    visa = 10000 + rand()%(99999-10000 + 1);
    return 10000 + rand()%(9999-1000 + 1);

    }

    [CODE]

    And this is the code I am useing to open and write to the save file, but all that happens is it opens a console window that says press any key to continue. When I press a key it shuts the window. Please Help

    Thank You
    WAckoWolf
    Last edited by WackoWolf; 11-14-2004 at 12:31 AM. Reason: NEED HELP PLEASE

  2. #2
    Epo
    Epo is offline
    Registered User
    Join Date
    Jun 2003
    Posts
    361
    I am finding it difficult to read your code since you did not, here, or in your last post, manage to fix the [CODE][/CODE] tags. Which makes me think you just copied and pasted the exact same question into a new thread to get it at the top of the list. This is worse than even just bumping. One thread is sufficient for a topic.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,767

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 04:44 PM
  2. Replies: 20
    Last Post: 07-24-2007, 12:47 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  5. Replies: 6
    Last Post: 03-02-2005, 02:45 AM

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