First I output data to a the file "f1.txt" with output file stream f1out. Then I want to copy the data from file "f1.txt" to the file "f2.txt". Then I want to output the content of both files through standard output to the monitor.
My problem is that it does not output anything from the files at all. I think that the rdbuf() is causing this but I do not know why. How can I fix this but still use the rdbuf() function?
i just searched rdbuf in the reference of this site and they give an example in which they backup cout's streambuf and reset it again after the operations. so i believe that you should do that too to get output.
here is the link: http://www.cplusplus.com/reference/iostream/ios/rdbuf/
I tried and did what the reference shows, but this does not solve the problem that it does not print out the content of the two files. The problem is still there. Do any others know why?
rdbuf() returns the private internal buffer of the stream class instance. You actually have to fill that buffer with read() readsome() operator>> etc. If you simply create a filestream object and then call rdbuf() it will not have any contents.
Edit: in the example from the link above the buffer is filled with the line:
cout << "This is written to the file";
As the internal buffer for the file stream object was swapped with the internal buffer for cin the string is sent to file instead of stdout.
I tried to do the same thing today and somehow I made it work. I will check your answers the next time as I encounter this problem. Thanks for your help guys.