Thread: Still can not write or read from save file

  1. #16
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by Epo
    Where is your WACKOFILE.dat being stored?

    Try specifiying the whole path, i.e. "C:\MyFolder1\MyFolde2\InHere\WACKOFILE.dat"
    Its being store right to the desktop, I am going to try what you just said and will let you know what happens

  2. #17
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by Epo
    Where is your WACKOFILE.dat being stored?

    Try specifiying the whole path, i.e. "C:\MyFolder1\MyFolde2\InHere\WACKOFILE.dat"
    I have no problem saveing the file, It seems that I just can't open the file to read and write to it. I am pulling my hair out now and I don't have much to start with in the first place. Please Help

  3. #18
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    If programA writes to fileA and fileA is then read by programB, you need to store fileA in the same directory as the exectuable file for programB or specify the whole file path for fileA when associating it with the ifstream you use to read it in programB. If you are storing fileA on the desktop, then it probably isn't in the same directory as the executable file for programB. If you can open fileA and see that you have written to fileA successfully, then please show the file name you associate with the ofstream to write fileA, and the filename you associate with the ifstream you use to read fileA in programB.

  4. #19
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by elad
    If programA writes to fileA and fileA is then read by programB, you need to store fileA in the same directory as the exectuable file for programB or specify the whole file path for fileA when associating it with the ifstream you use to read it in programB. If you are storing fileA on the desktop, then it probably isn't in the same directory as the executable file for programB. If you can open fileA and see that you have written to fileA successfully, then please show the file name you associate with the ofstream to write fileA, and the filename you associate with the ifstream you use to read fileA in programB.
    I am going to try what you just wrote, hope I do it right. After my then one day I am starting to lose it, lack of sleep, food, and drink isn't good for anyone. Will let you know what I did. Thank you

  5. #20
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by Epo
    Where is your WACKOFILE.dat being stored?

    Try specifiying the whole path, i.e. "C:\MyFolder1\MyFolde2\InHere\WACKOFILE.dat"
    I try saveing to "C:\Test\File\WACKOFILE.dat" but it will not save it there. It has to be something I am doing wrong. Anyone know what it is?

  6. #21
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Have you created the folders before you try to save the file? If I am not misstaken (might be), you must create all folders by hand or with some other instructions if they dont exist.

  7. #22
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by Epo
    Where is your WACKOFILE.dat being stored?

    Try specifiying the whole path, i.e. "C:\MyFolder1\MyFolde2\InHere\WACKOFILE.dat"
    I try what you wrote, And I made sure I made the folders first before I ran the program, but it will not save it to the folder "C:\Test\File\WACKOFILE.dat"

    Thios is killing me.

  8. #23
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    >>I try what you wrote, And I made sure I made the folders first before I ran the program, but it will not save it to the folder "C:\Test\File\WACKOFILE.dat"

    Did you write "C:\Test\File\WACKOFILE.dat" in your proram? If so try this: "C:\\Test\\File\\WACKOFILE.dat"

  9. #24
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by Epo
    Where is your WACKOFILE.dat being stored?

    Try specifiying the whole path, i.e. "C:\MyFolder1\MyFolde2\InHere\WACKOFILE.dat"
    I got it to save to a Folder on my C drive, and that works without any problems. But I still have the same problem as before It will not open the file. What in the world am I doing wrong?

  10. #25
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by WackoWolf
    I got it to save to a Folder on my C drive, and that works without any problems. But I still have the same problem as before It will not open the file. What in the world am I doing wrong?
    This the code I am useing to try and open the file, the code that I am useing to save the file works perfect. It the code I am useing to open to read and write to the save file that is not working. Here is the code. And Thank You all for the help that you have been giveing me.

    [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

    string clerkid = "";
    string name = "";
    string address = "";
    string city = "";
    string state = "";
    string hyphfill = "";

    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())

    {

    cout << "Unable to open file. Press <Enter> to quit." << endl;
    cin.get();
    return 1;


    getline(inFile,clerkid,'#');



    while(!inFile.eof())

    {

    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;

    }//end main

    [\CODE]

  11. #26
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Code:
    if(inFile.is_open())
    	
    	{
    
    	   cout << "Unable to open file. Press <Enter> to quit." << endl;
    cin.get();
    return 1;
    
    
    getline(inFile,clerkid,'#');
    Of course you wont read from the file, you are returning before, you read anything, so skip the cout, the cin.get() and return in this statement and it should work fine.

    Also: using inFile.eof() to control a loop is bad because you will get bad result, I believe you should use while(inFile) instead (correct me if wrong).

    Edit: Code tags are used as follows [ code ] Your code... [ /code ] but without spaces betwean [ and ]
    Last edited by Shakti; 11-14-2004 at 03:03 PM.

  12. #27
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by Shakti
    Code:
    if(inFile.is_open())
    	
    	{
    
    	   cout << "Unable to open file. Press <Enter> to quit." << endl;
    cin.get();
    return 1;
    
    
    getline(inFile,clerkid,'#');
    Of course you wont read from the file, you are returning before, you read anything, so skip the cout, the cin.get() and return in this statement and it should work fine.

    Also: using inFile.eof() to control a loop is bad because you will get bad result, I believe you should use while(inFile) instead (correct me if wrong).

    Edit: Code tags are used as follows [ code ] Your code... [ /code ] but without spaces betwean [ and ]
    There is no way I would be able to correct you if you are wrong. I try what you wrote I got rid or the error check, but all it does now is open the console window. And in the window it says "Press any key to continue" when I press a key the window shuts down. Really lost now.

  13. #28
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Did you get rid of the return 1; there too?? Otherwise the only way you should not get any result printed is because the file is empty.

  14. #29
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by Shakti
    Did you get rid of the return 1; there too?? Otherwise the only way you should not get any result printed is because the file is empty.
    Yes I made sure I rem that out also, plus I open the save file just to make sure it save to it and it did save text to the file.? It just is not my week.

  15. #30
    Registered User
    Join Date
    Oct 2004
    Posts
    56
    Quote Originally Posted by WackoWolf
    Yes I made sure I rem that out also, plus I open the save file just to make sure it save to it and it did save text to the file.? It just is not my week.
    I try something different, it seems to open the file but now its in a loop anyone have a idea?
    Here is the code I have now.

    [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

    string clerkid = "";
    string name = "";
    string address = "";
    string city = "";
    string state = "";
    string hyphfill = "";

    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())

    {

    // cout << "Unable to open file. Press <Enter> to quit." << endl;
    // cin.get();
    // return 1;


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




    while(!inFile.eof())

    {

    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;

    }//end main

    [\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