Board index » cppbuilder » TStream for a beginner

TStream for a beginner


2003-09-12 05:26:51 AM
cppbuilder109
Hi!
I'm kind of new to C++ Builder, but I have used Delphi before...
In Delphi there was quite easy to work with streams, but in C++ Builder
there wasn't...
So do anyone any guide to TStream or TFileStream for C++ Builder users...
I like to know how to save simple integer values and strings in a
TFileStream or so...
Please help!
Thanks...
 
 

Re:TStream for a beginner

Hi!
I'm kind of new to C++ Builder, but I have used Delphi before...
In Delphi there was quite easy to work with streams, but in C++ Builder
there wasn't...
So do anyone any guide to TStream or TFileStream for C++ Builder users...
I like to know how to save simple integer values and strings in a
TFileStream or so...
Please help!
Thanks...
 

Re:TStream for a beginner

"Samuel Genheden" < XXXX@XXXXX.COM >wrote in
Quote
Hi!

I'm kind of new to C++ Builder, but I have used Delphi before...
In Delphi there was quite easy to work with streams, but in C++
Builder there wasn't...

So do anyone any guide to TStream or TFileStream for C++ Builder
users... I like to know how to save simple integer values and strings
in a TFileStream or so...

Please help!
Thanks...




#include <fstream.h>
void WriteOutStuff(void)
{
ofstream MyFile("filename.txt") // define & open
MyFile << "Hello" << endl; // write a string
MyFile << 6 << endl; // write an integer
}
void ReadInStuff(void)
{
char AString[20]; // careful here - buffer overruns are easy
int AnInt;
ifstream MyFile("filename.txt") // define & open
MyFile>>AString; // read a string
MyFile>>AnInt; // read an integer
}
You can, of course, get as fancy as you want, but standard C++ file
streams aren't really tricky. Use BCB help on ofstream. It's not as
good as the help for their own libs, but look at the hierarchy at the
top of the page, and study the different classes to figure out what all
you can do.
Enjoy,
-G
 

{smallsort}