fstream and saving to a:\

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 13
Reputation: cap2361 is an unknown quantity at this point 
Solved Threads: 0
cap2361 cap2361 is offline Offline
Newbie Poster

fstream and saving to a:\

 
0
  #1
Feb 19th, 2005
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

  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: fstream and saving to a:\

 
0
  #2
Feb 19th, 2005
You may need to make it a:\\ because it thinks you are trying to 'escape' a character.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 13
Reputation: cap2361 is an unknown quantity at this point 
Solved Threads: 0
cap2361 cap2361 is offline Offline
Newbie Poster

Re: fstream and saving to a:\

 
0
  #3
Feb 19th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 199
Reputation: Tight_Coder_Ex is an unknown quantity at this point 
Solved Threads: 14
Tight_Coder_Ex's Avatar
Tight_Coder_Ex Tight_Coder_Ex is offline Offline
Junior Poster

Re: fstream and saving to a:\

 
0
  #4
Feb 19th, 2005
What exactly are you entering at:

  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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 13
Reputation: cap2361 is an unknown quantity at this point 
Solved Threads: 0
cap2361 cap2361 is offline Offline
Newbie Poster

Re: fstream and saving to a:\

 
0
  #5
Feb 19th, 2005
thanks to both!!!

outfile.open("a:\\filename");
this is line where I needed to have \\ to send to a:\
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC