I tried this, it worked.
First write file, then read file
content: 5, 5, "Hallo", 5, 3.1415...
read: 5, "Hallo", 5, 3.14...
//////////////////////////////////////////////////////////////////////
// Konstruktion/Destruktion
//////////////////////////////////////////////////////////////////////
ReadFortran::ReadFortran()
{
/* CFile file("test.file", CFile::modeRead);
AnyInt=ReadInt(f);
AnotherInt=ReadInt(f);
AnyString=ReadString(f);
file.Close();*/
}
ReadFortran::~ReadFortran()
{
}
float ReadFloat(CFile &f){
float buffer;
f.Read(&buffer,4);
return buffer;
};
int ReadInt(CFile &f){
short int buffer;
f.Read(&buffer,2);
return buffer;
};
CString ReadString(CFile &f){
short int length;
char *buffer,*last;
length = ReadInt(f);
buffer = (char*)new char[length+1];
f.Read((void*)buffer,length);
last=buffer+length;
*last=0;
CString x=buffer;
delete [] buffer;
return x;
};
void ReadFortran::WriteFile(CString FileName)
{
short int a=5;char b[]="Hallo";float c=3.14159265;
CFile f(FileName, CFile::modeWrite|CFile::modeCreate);
f.Write(&a,sizeof(a));
f.Write(&a,sizeof(a));
f.Write(&b[0],sizeof(b)-1);
f.Write(&a,sizeof(a));
f.Write(&c,sizeof(c));
f.Close();
}
void ReadFortran::ReadFile(CString FileName)
{
short int a=5;char b[]="Hallo";float c;
CString s,help;
CFile f(FileName, CFile::modeRead);
Line="This is the read line: ";
a=ReadInt(f);
help.Format("%s1: int #%3i# ",Line,a);
Line=help;
s=ReadString(f);
help.Format("%s2: string #%s# ",Line,s);
Line=help;
a=ReadInt(f);
help.Format("%s3: int #%3i#",Line,a);
Line=help;
c=ReadFloat(f);
help.Format("%s4: float #%10.5f#",Line,c);
Line=help;
}
Good luck
Greetings Andreas