944,092 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2817
  • C++ RSS
Feb 19th, 2005
0

fstream and saving to a:\

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  1. #include <fstream.h>
  2. #include <stdlib.h>
  3. #include <iostream.h>
  4.  
  5. int main()
  6. {
  7.  
  8. char filename[20] = "a:\filename.dat";
  9. char data[20];
  10.  
  11. cout << "Enter the filename: " ;
  12. cin >> filename;
  13. cout << endl << endl;
  14.  
  15. ofstream outfile;
  16.  
  17. outfile.open(filename);
  18.  
  19. if (outfile.fail())
  20. {
  21. cout << "The file was not successfully opened" << endl;
  22. exit(1);
  23. }
  24.  
  25. cout << "Input name: ";
  26. cin >> data;
  27. cout << endl;
  28.  
  29. outfile<<data;
  30. outfile.close();
  31. return 0;
  32. }
Last edited by alc6379; Feb 23rd, 2005 at 4:37 pm. Reason: added [code] tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cap2361 is offline Offline
13 posts
since Feb 2005
Feb 19th, 2005
0

Re: fstream and saving to a:\

You may need to make it a:\\ because it thinks you are trying to 'escape' a character.
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Feb 19th, 2005
0

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cap2361 is offline Offline
13 posts
since Feb 2005
Feb 19th, 2005
0

Re: fstream and saving to a:\

What exactly are you entering at:

C++ Syntax (Toggle Plain Text)
  1. 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.
Last edited by Tight_Coder_Ex; Feb 19th, 2005 at 1:39 pm. Reason: Be a little more specific with answer
Reputation Points: 47
Solved Threads: 17
Posting Whiz in Training
Tight_Coder_Ex is offline Offline
215 posts
since Feb 2005
Feb 19th, 2005
0

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:\
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cap2361 is offline Offline
13 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to get cursor position using c++ in Unix OS?
Next Thread in C++ Forum Timeline: reading key combinations





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC