Jump to content
Sign in to follow this  
357mag

Need a little help with my Welcome Program

Recommended Posts

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

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

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

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  

×