I'm just beginning down the road of programming, so take it easy on me. lol
I'm writing a program that will take information off of an input file(.txt), if the file name/path is correct it will calculate the needed values, and then print the results to an output file(.txt). It will check for errors after the user has input the file path and after the user enters the output file(.txt) that the program will print to. I am having trouble with the file error for the output file. Everything else is working fine, but for some reason(and I'm sure it's something small) it will print to the file but when I check to make sure that my if(!out) will catch errors with the file path, that portion doesn't work. I've been racking my brain for a couple days now. Writing, testing, rewriting, testing... I've written the program several different ways that have all led to the same problem, so I could deffinately use some help on this!!
Here is the portion of code that I'm having trouble with...
......
Expand|Select|Wrap|Line Numbers
- cout<<os.str();
- outputofstream out;
- string OutputFile;
- cout<<"Enter output file name (Use FULL file path): \n\n"; getline(cin, OutputFile);
- out.open(OutputFile.c_str());
- cout<<endl;
- if(!out){
- cout<<"Invalid output file.\n\n";
- cout<<"Ending program now.\n\n";
- exit(1);
- }
- else{
- out<<os.str();
- }
I hope that is easy to read, but again, I know the problem is somewhere in here. I had it working at one point but when I corrected another mistake I forgot what I had changed.(Rookie mistake lol) But according to the examples we did in class this looks exactly the same, but it is not working in the same what