Hi everybody!
I i'm trying to open a file (NEWFILE).Then i have to get the lines from two other files (FILE1 and FILE2) and write this lines on NEWFILE. After this i must write the content of NEWFILE on FILE1. So i need to write and read simultaneosly, but my compiler dosen't do this.Does anybody know how can get through this ?
THANK YOU!
Why don't you just open FILE1, FILE2 and NEWFILE and store the information you need from each one into variables? Then write out the information however you like.
I think the problem which he is facing is, he is not closing NEWFILE after writing to it and straightaway trying to read it which will not be possible.
The program that i'm writting is a little bit more complex , all these operations that i'm doing are included in a class.But i always close the NEWFILE. The problem is that i can't close the other two files wich are opened in the constructor.
If you have time here is the code. The member function "concatenate" has to read the lines from to files and write them to the first one. The member fuction "replaceWithCount" must read from two files and write to each one the number of characters in each line.The costructor has two string parameters wich represent the name of two files.THE PROBLEM IS DOESN'T WRITE ON FILE 1 and IT DOESN'T WRITE on both files the number of characters of their lines.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class GiugnoBis
{
private:
fstream f1;
fstream f2;
public:
GiugnoBis(string A, string B)
{
f1.open(A);
f2.open(B);
The first suggestion I will give you when using many file open/close operations is, use full paths. And i think this is the problem with your program. This way the files can be created in any directory which is a current directory. so you will create in one and try to read from other.
I did but i took off the paths so it's more simple for you to read it. When i tried it i used the paths of the files as file name with double slashes "\\".