Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7947349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:24:20+00:00 2026-06-04T01:24:20+00:00

I want to get characters of a string pointed by a position memory pointer

  • 0

I want to get characters of a string pointed by a position memory pointer in native C++:

For an equivalent implementation in C#, it will be:

int positionMemory = getPosition();

long size = 10;

string result = Marshal.PtrToStringAnsi(new IntPtr(positionMemory), size);

How can I produce the result in C++?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:24:22+00:00Added an answer on June 4, 2026 at 1:24 am

    I have a feeling this is going to cause problems down the road…

    The following should be more or less equivalent to the C# snippet you gave with the exception that the resulting string (stored in result) will still be ‘ANSI’ – it is not widened to UNICODE as would occur in the C# snippet.

    int positionMemory = getPosition();
    long size = 10;
    
    std::string result( reinterpret_cast<const char *>(positionMemory), size);
    

    Note that size characters will be placed in result – including '/0' characters, so if you try to pass the string to something expecting a C-style sting using c_str() you may get some unexpected results.

    Also, the usual caveats about using an int as a pointer (especially if you want this to have a hope of working on a 64-bit system) apply.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python, if I want to get the first n characters of a string
I want to get the last 5 digits/characters from a string. For example, from
I have a String and want to reverse it so that some characters get
I want to get the ASCII value of characters in a string in C#.
string s=abcdefghijklmnopqrstuvwxyz char f[]= (s.substr(s.length()-10,9)).c_str() ; I want to get the last 9 characters
I want to get the characters after the last / in an url like
I want to get the top #nr_of_rows - (int)(#nr_of_rows / 10 - 1) of
in Ruby, I just want to get rid of the last n characters of
I want to get the count of characters from the following words in the
Example String : as8d79asf5.dfdg dg s dgd2011/25klsdsj jdıo84823 jhgfkasfsf 2001/26llkasdjfıo; I want to get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.