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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bis How can I do 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 thank McMerfy for his answer and I hope he will answer it again. I don't really understand where I have to put the #10 and #13. I join a example of code, can you show me where I have to put it ?
// 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 ! ");
}
 
Bonjour Valerie,

Have you tried to replace
"You?" by "You?\n"
?

David
 
First: you don't need to set the FileStream's Position after you write to it. Write method sets the position after the last written character. So with your example it would be :
Code:
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());
  TextDateiFehr->Write(sVariableTwo.c_str(), sVariableTwo.Length());
  TextDateiFehr->Write(sVariableThree.c_str(), sVariableThree.Length());

  // Adding a line break:
  TextDateiFehr->Write(AnsiString("\n").c_str(), AnsiString("\n").Length());
  // or you could do it like this
  // TextDateiFehr->Write(AnsiString(Char(10)).c_str(),1);

  TextDateiFehr->Write(sVariableFour.c_str(), sVariableFour.Length());
  delete TextDateiFehr;
}
Something like this... Hope that helps.

--- markus.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top