Thread: Cannot convert string to AnsiString

  1. #1
    Registered User
    Join Date
    Feb 2006

    Cannot convert string to AnsiString

    I am writing a program that takes strings form a file and displays them in an edit box on a form. however when i try and output them i get the error message Cannot convert 'string' to 'AnsiString' I'm unsure of the difference and am not sure how to rectify this problem. Any suggestions would be appreciated. I've included the code if it helps.
      string str;
      ifstream myfile("Entry.txt");
      if (!myfile)
        ShowMessage ("Error opening file");
      while (! myfile.eof())
         Form1->Edit1->Text = str
         Form1->Edit2->Text = str;
         Form1->Edit3->Text = str;
         Form1->Edit4->Text = str;
         Form1->Edit5->Text = str;

  2. #2
    Registered User
    Join Date
    Jan 2005
    Try the c_str() function of string which converts to a const char*. Most likely you can assign a C style string to AnsiString.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cannot convert 'AnsiString' to 'const char *'
    By codexparse in forum C++ Programming
    Replies: 0
    Last Post: 11-03-2007, 06:44 PM
  2. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  3. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  4. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM