char s_russian[] = { 'à','á','â','ã','ä','å','¸','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','ø','ù','ú','û','ü','ý','þ','ÿ' }; std::string password_chars = ""; password_chars += s_russian; Edit2->Text = password_chars; 

The compiler produces an error:

[C ++ Error] Unit1.cpp (67): E2034 Cannot convert '_STL :: string' to 'AnsiString'

  • Russian characters are incorrectly copied - aaa

2 answers 2

The compiler writes that it cannot convert std::string to AnsiString (and Edit2->Text is AnsiString ). Make Edit2->Text = password_chars.c_str() ;

  • I have at the end of the line some incomprehensible character, what is it? I insert it into the browser line - a space. - aaa
  • The char * string must end with a null character, otherwise it will be considered incomplete, and garbage that is in memory after the characters that you initialized can enter into it. Add the '\0' character to the end of the array. - Vladimir Pavluk
  • @ Shouldn't it be added automatically? - aaa
  • one
    And why should it be added automatically if you specify a string in an array? After all, the compiler does not understand that you want to make a string from this array. Now, if you had written char s_russian[] = "àáâãä叿çèéêëìíîïðñòóôõöøùúûüýþÿ"; , then the compiler would add 0 at the end of the line automatically. - Vladimir Pavluk
  • Thank you, I will know) - aaa

If possible, it is better not to interfere with the Border AnsiString with std::string . And instead of AnsiString use just a String , which will unfold in Ansi- or Unicode- , depending on the project settings.

In this case, the problem can be solved by creating an AnsiString object using a constructor that takes a pointer to a char and the number of elements.

 Edit2->Text = AnsiString(s_russian, sizeof(s_russian)); 

Or replace the original array with a string literal:

 const char* s_russian = "русские_буквы"; Edit2->Text = s_russian; 
  • I agree, but this is another question: whether or not the author should do so :-) - Vladimir Pavluk
  • @VladimirPavluk to know how to get around an error is good, but even better - avoid situations that provoke errors :) - αλεχολυτ
  • So does not display password_chars - aaa
  • [C ++ Error] Unit1.cpp (68): E2285 Could not find a match for 'AnsiString :: AnsiString (_STL :: string, unsigned int)' - aaa
  • @ Eugene, why do you have the first argument std::string , if s_russian is an array of char ? - αλεχολυτ