mình có thể đưa thẳng vào textbox bằng hàm Text nhưng nó chỉ sử dụng String^ hoặc System::String
.Mấy bác giúp tôi với .
test5.h
#pragma once
#include <iostream>
#include <fstream>
namespace test4 {
using namespace std;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for test5
/// </summary>
public ref class test5 : public System::Windows::Forms::Form
{
public:
test5(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
string* docFile()
{
ifstream doc("data.txt");
String^ a[5] ;
if (doc.fail()) cout << "Not exist" << endl;
else
{
int i = 0;
while (!doc.eof())
{
doc >> a[i];
i++;
}
}
return a;
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~test5()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(118, 58);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 0;
this->textBox1->Text = "" ;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(118, 101);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(100, 20);
this->textBox2->TabIndex = 1;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(43, 61);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(36, 13);
this->label1->TabIndex = 2;
this->label1->Text = L"Line 1";
this->label1->Click += gcnew System::EventHandler(this, &test5::label1_Click);
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(43, 104);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(36, 13);
this->label2->TabIndex = 3;
this->label2->Text = L"Line 2";
this->label2->Click += gcnew System::EventHandler(this, &test5::label2_Click);
//
// test5
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 261);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->Name = L"test5";
this->Text = L"test5";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
test5.cpp
#include "test5.h"
using namespace System;
using namespace System::Windows::Forms;
[STAThread]
int main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
test4::test5 form;
Application::Run(% form);
return 0;
}
data.txt
Nguyen Van
Huynh Van