antiblock
Cyphriun
  • Chatbox

    Did you check out our Discord? https://discord.gg/FFdvMjk9xA
    You don't have permission to chat.
    Load More
Sign in to follow this  
V¡®u§

Como converter AnsiString para char[] (C ++ Builder)

1 post in this topic

O exemplo a seguir leva um Button, um Label e 4 Edits no Form. Quando o usuário dá um clique no botão, o programa realiza algumas conversões entre AnsiString e char[] e vice-versa:

//-------------------------------------------------------------

#include

#pragma hdrstop

#include "Unit1.h"

//-------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

//-------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

//-------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)

{

Edit1 -> Text = "String inicial de Edit1";

}

//-------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

char buffer[100] = "Valor inicial de buffer";

Label1 -> Caption = buffer;

Edit2 -> Text = buffer[0];

// converte Text de AnsiString para char*

strcpy (buffer, Edit1->Text.c_str());

Edit3 -> Text = buffer[0];

Edit4 -> Text = (String) buffer[0]+ buffer[1] + buffer[2];

}

//-------------------------------------------------------------

Share this post


Link to post
Share on other sites
antiblock
diamwall

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this