output file failing to open

anyone have any help on why my output file is failign to open. The text file exists and the hyperlink is correct\

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

int main(){

using namespace std;

string line;
string useradvice;
ifstream in_stream;
fstream out_stream;

out_stream.open("C:\\Documents and Settings\\Administrator\\Desktop\\HW\\HW4\\hw4pr5input.txt", ios::in | ios::out);

if (in_stream.fail())
cout << "Input file opening failed.\n";
system ("pause");

out_stream.open("C:\\Documents and Settings\\Administrator\\Desktop\\HW\\HW4\\hw4pr5input_output.txt");
if (out_stream.fail())
cout << "Output file opening failed.\n";
system ("pause");

cout << "enter programming advice now, press enter twice:" << endl;
while ( getline (out_stream,line) )
cout << line << endl;
cout << "Write a piece another piece of advice. Press the Enter key twice:" " ";

getline(cin, useradvice); //program function
out_stream.open("hw4pr5input.txt", ios::out | ios::trunc );
//myfile.clear(); //
out_stream << useradvice;

return 0;
...the hyperlink is correct...

This ain't HTML.

Why do you check if in_stream failed when you only default constructed it?

Remember to close your files before opening a new one.

And I'm not sure how well the rest of the code will work as you intended.
this is a beginner forum correct? thanks. used the term hyperlink to refer to pathway. so what do you mean by only default constructed it? why are people so hypersensitive to a beginner
Default construction means creating an object without parameters, like ifstream in_stream;.

Sorry if I sounded stingy or something. I wrote the way I did (specifically "This ain't HTML") as a play on some old thread that I now feel like a donkey's butt about.

File I/O isn't my strong point, but I am pretty sure you need to close your files before opening a new one with the same object, namely, after your first if statement.
Two streams are defined:
ifstream in_stream;
fstream out_stream;

The program attempts to open out_stream and then checks whether in_stream was opened ok.
I think you meant to refer to the same stream both times?
I'd guess that the first out_stream.open is supposed to in_stream.open


while ( getline (out_stream,line) ) -> while ( getline (in_stream,line) )
Topic archived. No new replies allowed.