| | |
fstream and saving to a:\
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2005
Posts: 13
Reputation:
Solved Threads: 0
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)
#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; }
Last edited by alc6379; Feb 23rd, 2005 at 4:37 pm. Reason: added [code] tags
What exactly are you entering at:
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.
C++ Syntax (Toggle Plain Text)
cin >> filename;
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
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: How to get cursor position using c++ in Unix OS?
- Next Thread: reading key combinations
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





