Error C++: E2034 Cannot Convert 'wchar_t *' to 'const char *'

Asked

Viewed 1,547 times

1

When executing a C++ code these two problems occur:

- [BCC32 Error] USerialCommunication.cpp(96): E2034 Cannot convert 'wchar_t *' to 'const char *'
- [BCC32 Error] USerialCommunication.cpp(96): E2342 Type mismatch in parameter '__src' (wanted 'const char *', got 'wchar_t *')  

Source Code:

void __fastcall TFSerialPort::EnviarClick(TObject *Sender)
{
        char buff[100];    
        //Converte uma string em array.
        strcpy(buffer, EdCommand->Text.c_str());
}

Statement by Edcommand: TEdit *EdCommand;

Buffer declaration: char buffer[100];

Error occurs on the line of strcpy.

Note: The source code was made in C++ Builder 6 and I am trying to run in Embarcadero XE2

  • No, the statement of buffer is char buff[100]; and the call from strcpy is buffer. Possibly the error is there. What is the type of property TEdit->Text. The error may be in c_ str.

  • Actually this char Buff[100] statement is correct. The char buffer[100] variable is outside this code. The error solution posted below, after a while I managed to resolve. Thank you so much for the help.

1 answer

1


To resolve, I converted to Ansistring:

Before:

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

Afterward:

strcpy(buffer, AnsiString(EdCommand->Text).c_str());
  • That’s what I was thinking. The kind of TEdit::Text was incompatible with the c_str(). Don’t forget to accept the answer.

  • You can leave, in two days I accept. Thanks @bigown

Browser other questions tagged

You are not signed in. Login or sign up in order to post.