Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the equivalent of endl with TFileStream

Status
Not open for further replies.

BigValerie

Programmer
Jul 10, 2002
6
DE
I would like to go to the next line in a text file that I write with the component TFileStream of Borland C++ Builder 4. I tried with \n, Char(10) but it make only a strange symbol in my file. I join an exemple of code, has anybody the answer ?
// Example of Program
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString sVariableOne = "- How";
AnsiString sVariableTwo = "are";
AnsiString sVariableThree = "you ?";
//I would like a new line here
AnsiString sVariableFour = "- Fine, Thank you";
TFileStream *TextDateiFehr =
new TFileStream("D:\\MesProgrammes\\Daten\\EssaiValEndl",fmCreate);
int iPosition=0;
TextDateiFehr->Write(sVariableOne.c_str(),sVariableOne.Length());
iPosition += 6;
TextDateiFehr->Position=iPosition;
TextDateiFehr->Write(sVariableTwo.c_str(),sVariableTwo.Length());
iPosition += 4;
TextDateiFehr->Position=iPosition;
TextDateiFehr->Write(sVariableThree.c_str(),sVariableThree.Length());
iPosition += 6;
TextDateiFehr->Position=iPosition;
TextDateiFehr->Write(sVariableFour.c_str(),sVariableFour.Length());

delete TextDateiFehr;

ShowMessage(" Der Programm ist durch ! ");
}
 
Why not use standard streams?
Code:
AnsiString sVariableOne   = "- How";
AnsiString sVariableTwo   = "are";
AnsiString sVariableThree = "you ?";
AnsiString sVariableFour  = "- Fine, Thank you";

ofstream TextDateiFehr;

TestDateiFehr.open("D:\\MesProgrammes\\Daten\\EssaiValEndl",ios::out);
TextDateiFehr << sVariableOne.c_str() << &quot; &quot;; // These lines could be combined
TextDateiFehr << sVariableTwo.c_str() << &quot; &quot;;
TextDateiFehr <<  sVariableThree.c_str() << ios::endl;
TextDateiFehr << sVariableFour.c_str() << ios::endl;

ShowMessage(&quot; Der Programm ist durch ! &quot;);
[code]

Or something like that. You will need to add [code]#include <fstream>
in your header file. In Builder 5 you need to have the ios:: but in Builder 3 you didn't. I don't know about 4. James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that they think I am now
qualified to do anything with nothing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top