Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AnsiString - char* transition 1

Status
Not open for further replies.

ddvlad

Programmer
Mar 12, 2003
71
0
0
RO
Hi, I'm doing someone a favor writing a program in Borland C++ Builder 5. Is there any way to convert between char* and AnsiString? I am using fstream to read words from a file (it's a hangman game) and I couldn't find any method that reads an AnsiString instead of a char*. If there is any other wrapper for files please let me know. I just need a starting point; I'm quite familiar with C and C++, although I haven't been doing much Windows programming in them lately.

Thanks in advance,
Vlad

--
People here are not only very knowledgeable, but also polite and helpful. My sincere congratulations to everyone.
 
If you mean convert from char* to AnsiString, just an assignment statement will work:
Code:
  char *s = "this is a test";
  AnsiString MyAnsiString = s;

To go the other way, use the c_str() method:

Code:
strcpy(s,MyAnsiString.c_str());
 
Thanks a lot. I wouldn't have thought simple assignment would work, since C is all picky about strings. And I definitely wouldn't have thought of c_str().

--
People here are not only very knowledgeable, but also polite and helpful. My sincere congratulations to everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top