我想问这个小程序的一些帮助。我正在使用Embarcadero RAD XE2并尝试使用按钮和文本框来构建小型窗体。机制很简单,我在文本框中编写了一些东西,并且当我单击按钮时,我希望将这些东西写入到.txt文件中。如何使用TEdit(文本框)编写文本文件
这是形式的我.cpp文件中的代码:
//---------------------------------------------------------------------------
#include <fmx.h>
#include <iostream.h>
#include <fstream.h>
#include <String>
#pragma hdrstop
#include "STRTEST.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
int writefile(String A)
{
ofstream myfile;
myfile.open("D://example.txt");
myfile << A;
myfile.close();
return 0;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String mystr = Edit1->Text+';';
writefile(mystr);
Form1->Close();
}
//---------------------------------------------------------------------------
现在,我有这样的问题:在行 “myStr的< < A;”我得到这个错误。
[BCC32错误] STRTEST.cpp(13):E2094 '运算符< <' 不 类型 '的ofstream' 的类型的参数 '的UnicodeString' 完全解析器 上下文 STRTEST.cpp实现(10) :解析:int writefile(UnicodeString)
我不知道该怎么办。如果我用直接字符串替换A,即函数写入文件完美无瑕,并用该特定字符串写入文件。
任何人都知道如何解决这个问题?