DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   fstream and saving to a:\ (http://www.daniweb.com/forums/thread18895.html)

cap2361 Feb 19th, 2005 12:33 pm
fstream and saving to a:\
 
when I complile this program and then try to run it I get error LNK1201. So I started over and left it complile to c:\ and when I try to run it I get file could not be opened. I think the objective is to compile on c:\ and save data file on a:\. what am I doing wrong? thx

#include <fstream.h>
#include <stdlib.h>
#include <iostream.h>

int main()
{

        char filename[20] = "a:\filename.dat";
        char data[20];

        cout << "Enter the filename: " ;
        cin >> filename;
        cout << endl << endl;

        ofstream outfile;

        outfile.open(filename);

        if (outfile.fail())
        {
                cout << "The file was not successfully opened" << endl;
                exit(1);
        }

        cout << "Input name: ";
        cin >> data;
        cout << endl;

        outfile<<data;
        outfile.close();
        return 0;
}

winbatch Feb 19th, 2005 1:03 pm
Re: fstream and saving to a:\
 
You may need to make it a:\\ because it thinks you are trying to 'escape' a character.

cap2361 Feb 19th, 2005 1:12 pm
Re: fstream and saving to a:\
 
Quote:

Originally Posted by winbatch
You may need to make it a:\\ because it thinks you are trying to 'escape' a character.



thx but it didn't work. still writes to c:\ drive

Tight_Coder_Ex Feb 19th, 2005 1:33 pm
Re: fstream and saving to a:\
 
What exactly are you entering at:

cin >> filename;
If you are not specific (entering drive designator) it will use whatever the default drive is when the application was launched. Probably in your case "c:\".

winbatch is correct with his response, but don't make the mistake of doing the same thing when prompted at the console. Double back slashes have a completely different meaning in that context.

cap2361 Feb 19th, 2005 2:20 pm
Re: fstream and saving to a:\
 
thanks to both!!!

outfile.open("a:\\filename");
this is line where I needed to have \\ to send to a:\


All times are GMT -4. The time now is 2:33 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC