F
Frédéric Manzanares
hello,
my problem: I want to habe one Class with write and read in a file. i have
overloaded
the operator >> and <<.
class c_File
{
public :
fstream fs;
......
public :
....
friend void operator >> (c_File& ,string& );
friend void operator << (c_File& ,const char * );
....
}
void operator <<(c_File& myFile, const char* out )
{
myFile.fs<<out;
}
void operator >>(c_File& myFile, string& out)
{
int c;
string s;
getline(myFile.fs,s);
out=s;
}
main.C
{
c_File oFile;
string s;
oFile.OpenFile("file_sample.txt",ios::in|ios:ut|ios::app );
oFile<<"hey baby!";
oFile>>s;
cout<<s<<endl;
}
The result is :
The file was empty!!
in the file " hey baby"
but the "cout" do nothing !!
i have tried with seekp/seekg(0,ios::end), flush and sync ... but it don't
do better.
i can't see the "s" variable. There is nothing in it
i use xlC vers. 6 and aix. 5.2
have you any idea ??
thank you a lot for your help
Frédéric
my problem: I want to habe one Class with write and read in a file. i have
overloaded
the operator >> and <<.
class c_File
{
public :
fstream fs;
......
public :
....
friend void operator >> (c_File& ,string& );
friend void operator << (c_File& ,const char * );
....
}
void operator <<(c_File& myFile, const char* out )
{
myFile.fs<<out;
}
void operator >>(c_File& myFile, string& out)
{
int c;
string s;
getline(myFile.fs,s);
out=s;
}
main.C
{
c_File oFile;
string s;
oFile.OpenFile("file_sample.txt",ios::in|ios:ut|ios::app );
oFile<<"hey baby!";
oFile>>s;
cout<<s<<endl;
}
The result is :
The file was empty!!
in the file " hey baby"
but the "cout" do nothing !!
i have tried with seekp/seekg(0,ios::end), flush and sync ... but it don't
do better.
i can't see the "s" variable. There is nothing in it
i use xlC vers. 6 and aix. 5.2
have you any idea ??
thank you a lot for your help
Frédéric