[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppBuilderOutputAddress

(C++ Builder) How do I display a memory address on screen?

Convert the memory address to a std::string, then convert the std::string to a String.

Note that when converting this address to either an integer or a String, this yields the same result.

  1. include <string>
  2. include <sstream>
std::string toString(const String& ansi) { const char * myChar = ansi.c_str(); const std::string myString = myChar; return myString; } //--------------------------------------------------------------------------- String toAnsiString(const std::string& myString) { const char * myChar = myString.c_str(); const String myAnsi = myChar; return myAnsi; } //--------------------------------------------------------------------------- std::string addressToString(const void* x) { std::ostringstream o; if (!(o << x)) return "ERROR"; return o.str(); } //--------------------------------------------------------------------------- int addressToInt(const void* x) { const std::string myString = addressToString(x); return atoi(myString.c_str()); } //--------------------------------------------------------------------------- String addressToAnsi(const void* x) { const std::string myString = addressToString(x); return toAnsiString(myString.c_str()); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { ShowMessage(addressToInt(this)); ShowMessage(addressToAnsi(this)); } //---------------------------------------------------------------------------


Other code snippets



last edited (November 4, 2006) by bilderbikkel, Number of views: 2225, Current Rev: 3 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.