357mag 2 Posted May 21, 2023 I've got a program where the user enters his first name in an Edit box. Then he presses the button entitled Show Message and I will show him a Welcome Message. I'm having some trouble with coding the first name. Builder says Could not find a match for string::basic(const string&). Here is what I have so far: #include <vcl.h> #pragma hdrstop #include "welcome_program.h" #include <iostream> #include <string> using namespace std; //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TFormWelcome *FormWelcome; //--------------------------------------------------------------------------- __fastcall TFormWelcome::TFormWelcome(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TFormWelcome::ButtonShowMessageClick(TObject *Sender) { string firstName = AnsiString(EditFirstName->Text); } Share this post Link to post
357mag 2 Posted May 21, 2023 I got it going! This works: #include <vcl.h> #pragma hdrstop #include "welcome_program.h" #include <iostream> //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TFormWelcome *FormWelcome; //--------------------------------------------------------------------------- __fastcall TFormWelcome::TFormWelcome(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TFormWelcome::ButtonShowMessageClick(TObject *Sender) { AnsiString firstName = EditFirstName->Text; LabelMessage->Caption = "Welcome to C++ Programming " + firstName + "!"; } Share this post Link to post
Roger Cigol 107 Posted May 22, 2023 Same advice as the string integer posting. Use String rather than AnsiString(). You only need to use AnsiString variables if you specifically want to represent text using only 8 bit Ansi encoding. These days that is a rare occurrence. Share this post Link to post