The <<
and >>
operators for String
values are only implemented if VCL_IOSTREAM
is defined in the project. Even then, it still would not work because you are using ofstream
, which does not accept Unicode data (String
is an alias for UnicodeString
in CB2009+). You have to use wofstream
instead, and then use String::c_str()
to stream the value:
//---------------------------------------------------------------------------
#include <fmx.h>
#include <iostream>
#include <fstream>
#include <string>
#pragma hdrstop
#include "STRTEST.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
int writefile(System::String A)
{
std::wofstream myfile;
myfile.open(L"D://example.txt");
myfile << A.c_str();
myfile.close();
return 0;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
System::String mystr = Edit1->Text + L";";
writefile(mystr);
Close();
}
//---------------------------------------------------------------------------