c++builder 读写文件类

本文详细介绍了如何使用C++Builder中的TStreamReader和TStreamWriter类读取和写入文件,包括创建流写入器和读取器,存储标题和正文文本,并在加载时读取文件内容。

c++builder 读写文件类

TStreamReader、TStreamWriter
读取一行
http://docwiki.embarcadero.com/CodeExamples/XE8/en/StreamCharRdWr_%28C%2B%2B%29
void __fastcall TMainForm::btSaveClick(TObject *Sender)
{
    TStreamWriter* writer;
 
    /* Create a new stream writer directly. */
    writer = new TStreamWriter("local_file.txt",
        false, TEncoding::UTF8, 1024);
 
    /* Store the title and then the text. */
    writer->WriteLine(edtTitle->Text);
    writer->Write(mmText->Text);
 
    /* Close and Free the writer. */
    delete writer;
}
 
void __fastcall TMainForm::btLoadClick(TObject *Sender)
{
    TStreamReader* reader;
 
    /* Create a new stream writer directly. */
    reader = new TStreamReader("local_file.txt",
        TEncoding::UTF8);
 
    /* Read the title and then the actual text. */
    edtTitle->Text = reader->ReadLine();
    mmText->Text = reader->ReadToEnd();
 
    /* Close and Free the writer. */
    delete reader;
}

 

TStringReader、
TStringWriter


转载于:https://www.cnblogs.com/cb168/p/4645706.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值