Thread: Still can not write or read from save file

  1. #31
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    the cause of the loop is the eof is never reached... try "pulling" the info from the file before printing to the screen.

  2. #32
    Registered User
    Join Date
    Oct 2004
    Posts
    56

    Post

    Quote Originally Posted by CasinoDuck
    the cause of the loop is the eof is never reached... try "pulling" the info from the file before printing to the screen.
    [QUOTE=WackoWolf] Now I am really lost. How do I do that?[\QUOTE]

  3. #33
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    instead of the while loop i put this loop in and it worked

    for(i=0;i<max;i++,count++){
    indata>>namefirst>>namelast>>city>>zipcode;

    listnamefirst[i]=namefirst;
    listnamelast[i]=namelast;
    listcity[i]=city;
    listzipcode[i]=zipcode;

    if(indata.eof()){
    ++count;
    break;}
    }

    or even just:

    for(i=0;i<max;i++){
    indata>>listnamefirst[i]>>listnamelast[i]>>listcity[i]>>listzipcode[i];

    if(indata.eof()){
    break;}
    }
    Last edited by CasinoDuck; 11-14-2004 at 06:58 PM.

  4. #34
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by CasinoDuck
    instead of the while loop i put this loop in and it worked

    for(i=0;i<max;i++,count++){
    indata>>namefirst>>namelast>>city>>zipcode;

    listnamefirst[i]=namefirst;
    listnamelast[i]=namelast;
    listcity[i]=city;
    listzipcode[i]=zipcode;

    if(indata.eof()){
    ++count;
    break;}
    }

    or even just:

    for(i=0;i<max;i++){
    indata>>listnamefirst[i]>>listnamelast[i]>>listcity[i]>>listzipcode[i];

    if(indata.eof()){
    break;}
    }
    How did you do it? I rem out the while loop and I got build errors? Do I also have to rem something else?

    Thank you

  5. #35
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    i think the difference is that i used arrays... maybe thats what your asking?

    like this:

    string listnamefirst[100];
    string listnamelast[100];
    string listcity[100];
    long int listzipcode[100];
    Last edited by CasinoDuck; 11-14-2004 at 07:14 PM.

  6. #36
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by CasinoDuck
    i think the difference is that i used arrays... maybe thats what your asking?

    like this:

    string listnamefirst[100];
    string listnamelast[100];
    string listcity[100];
    long int listzipcode[100];
    Now for the DUMB question of the last couple of days. Were do I put them?

  7. #37
    Registered User
    Join Date
    Nov 2004
    Posts
    4
    Now for the DUMB question of the last couple of days. Were do I put them
    int main()
    {
    string listnamefirst[100];
    string listnamelast[100];
    string listcity[100];
    long int listzipcode[100];
    Last edited by CasinoDuck; 11-14-2004 at 07:25 PM.

  8. #38
    Registered User
    Join Date
    Oct 2004
    Posts
    56

    Post

    Quote Originally Posted by CasinoDuck
    int main()
    {
    string listnamefirst[100];
    string listnamelast[100];
    string listcity[100];
    long int listzipcode[100];
    [QUOTE=WackoWolf]

    this is what I now have for the code, let me know if this is what you talking about.

    Thank You

    [CODE]
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <ctime>
    #include <cstdlib>
    #include <fstream>
    #include <algorithm>
    int getNumbers(int &);


    using namespace std;
    int main()

    {

    //declare Variables
    int void()

    string clerkid = "";
    string name = "";
    string address = "";
    string city = "";
    string state = "";
    string hyphfill = "";
    string listnamefirst[100];
    string listnamelast[100];
    string listcity[100];
    long int listzipcode[100];
    int max=100;
    int count=0;

    int zip = 0;
    int ssn = 0;
    int visa = 0;
    int pin = 0;

    //opens file CCApp.txt

    ifstream inFile;
    inFile.open("C:\\Test\\File\\WACKOFILE.dat", ios::in);
    if(inFile.is_open())

    {



    char buffer [ 30 ];
    inFile.getline ( buffer , 30 , '#' );




    //while(!inFile.eof())

    for(i=0;i<max;i++,count++){
    indata>>namefirst>>namelast>>city>>zipcode;

    listnamefirst[i]=namefirst;
    listnamelast[i]=namelast;
    listcity[i]=city;
    listzipcode[i]=zipcode;

    if(indata.eof()){
    ++count;
    /break;}

    {

    inFile>>ssn;
    inFile.ignore(1);
    getline(inFile,name,'#');
    getline(inFile,address,'#');
    getline(inFile,city,'#');
    getline(inFile,state,'#');

    inFile>>zip;
    inFile.ignore(1);
    inFile>>pin;
    inFile.ignore(1);
    inFile>>visa;
    inFile.ignore(2);


    cout<<left<<setw(25)<<setfill(' ')<<"NAME"<<" "<<setw(25)<<"ADDRESS"<<" "<<left<<setw(16)<<"CITY"<<" "<<setw(2)<<
    left<<"ST"<<" "<<setw(5)<<left<<"ZIP";


    cout<<left<<setw(25)<<setfill('-')<<hyphfill<<" "<<setw(25)<<setfill('-')<<hyphfill<<" "<<left<<setw(16)<<setfill('-')<<hyphfill<<" "<<setw(2)<<left<<setfill('-')<<hyphfill<<" "<<
    setw(5)<<left<<setfill('-')<<hyphfill;

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

    cout<<setw(7)<<left<<"CLERKID"<<" "<<setw(9)<<left<<setfill(' ')<<"SSN"<<" "<<setw(4)<<left<<setfill(' ')<<"PIN"<<" "<<setw(5)<<left<<setfill(' ')<<"VISA"<<" "<<endl;

    cout<<setw(7)<<left<<setfill('-')<<hyphfill<<" "<<setw(9)<<left<<setfill('-')<<hyphfill<<" "<<setw(4)<<left<<setfill('-')<<hyphfill<<" "<<setw(5)<<left<<setfill('-')<<hyphfill<<" "<<endl;

    cout << setw(7) << left << setfill(' ') << clerkid
    <<" "<<setw(9)<<right<<setfill('0')<<ssn<<" "<<setw(4)<<left<<setfill(' ')<<pin<<" "<<setw(5)<<left<<setfill(' ')<<visa<<" "<<endl;




    cout<<endl;
    cout<<endl;

    //getline(inFile,clerkid,'#');



    }
    }
    else

    {cout<<"File not opened"<<endl;}
    inFile.close();

    cout << endl;
    return 0;
    [\CODE]

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, 03:44 PM
  2. Replies: 20
    Last Post: 07-24-2007, 11:47 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Replies: 6
    Last Post: 03-02-2005, 02:45 AM