The traditional problem with reading & writing files with iostream...
I try to read "slav.txt" file, then paste this in "slav2.txt".
The text in "slav.txt" is "Hello world", at console i receive "Helloworldrl" (with nospace and "rl" at end), and in "slav2.txt" i receive "drl"
This is my code:
#include <iostream>
#include <fstream>
#include <conio.h>
using namespace std;
class File
{
ifstream f1;
ofstream f2;
char s[200];
public:
void ShowFile(char *nume);
void ReadInFile(char *nume);
};
void File::ReadInFile(char *nume)
{
f2.open(nume);
for(int i=0; i<strlen(s); i++)
{
f2<<s[i];
}
f2.close();
}
void File::ShowFile(char *nume)
{
f1.open(nume);
if(f1.fail())
{
cout<<"Error opening file!";
getch();
exit(1);
}
while(!f1.eof())
{
for(int i=0; i<strlen(s); i++)
{
f1>>s[i];
cout<<s[i];
}
}
f1.close();
}
int main()
{
File F;
F.ShowFile("slav.txt");
F.ReadInFile("slav2.txt");
getch();
return 0;
}