我会使用 TSaveTextFileDialog 将我的 2 个整数和浮点数组分别保存到“csv 样式”.txt 文件中。我正在尝试使用 Windows VCL 应用程序在 C++ Builder 中执行此操作。这是我的尝试:
__fastcall TForm6::TForm6(TComponent* Owner)
: TForm(Owner)
{
saveTxtDlg = new TSaveTextFileDialog(this);
TStrings* encodings = new TStringList();
encodings->AddObject("UTF8", TEncoding::UTF8);
saveTxtDlg->Encodings->Assign(encodings);
saveTxtDlg->Filter = "Text files (*.txt)|*.TXT";
}
void __fastcall TForm6::Button2Click(TObject *Sender)
{
if (saveTxtDlg->Execute(this->Handle))
{
String filename = saveTxtDlg->FileName + ".txt";
int encIndex = saveTxtDlg->EncodingIndex;
TEncoding* enc = dynamic_cast<TEncoding*>
(saveTxtDlg->Encodings->Objects[encIndex]);
int x[] = {1, 2, 3, 4, 5};
float y[] = {10.1, 20.5, 30.8, 40.7, 50.2};
for (int i = 0; i < 5; i++) {
std::string s = std::to_string(x[i]) + "," + std::to_string(y[i]);
s.SaveToFile(filename, enc);
}
}
}
但是字符串没有“SaveToFile”的成员。请问我怎么解决?先感谢您。