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 6005311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:22:48+00:00 2026-05-23T01:22:48+00:00

I am retrieving the environment variables in win32 using GetEnvironmentStrings() . It returns a

  • 0

I am retrieving the environment variables in win32 using GetEnvironmentStrings(). It returns a char*.

I want to search this string(char pointer) for a specific environmental variable (yes I know I can use GetEnvironmentVariable() but I am doing it this way because I also want to print all the environment variables on the console aswell – I am just fiddling around).

So I thought I would convert the char* to an std::string & use find on it (I know I can also use a c_string find function but I am more concerned about trying to copy a char* into a std::string). But the following code seems to not copy all of the char* into the std::string (it makes me think there is a \0 character in the char* but its not actually the end).

char* a = GetEnvironmentStrings();
string b = string(a, sizeof(a));
printf( "%s", b.c_str() );  // prints =::= 

Is there a way to copy a char* into a std::string (I know I can use strcpy() to copy a const char* into a string but not a char*).

  • 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-05-23T01:22:49+00:00Added an answer on May 23, 2026 at 1:22 am

    You do not want to use sizeof() in this context- you can just pass the value into the constructor. char* trivially becomes const char* and you don’t want to use strcpy or printf either.

    That’s for conventional C-strings- however GetEnvironmentStrings() returns a bit of a strange format and you will probably need to insert it manually.

    const char* a = GetEnvironmentStrings();
    int prev = 0;
    std::vector<std::string> env_strings;
    for(int i = 0; ; i++) {
        if (a[i] == '\0') {
            env_strings.push_back(std::string(a + prev, a + i));
            prev = i;
            if (a[i + 1] == '\0') {
                break;
            }
        }
    }
    for(int i = 0; i < env_strings.size(); i++) {
        std::cout << env_strings[i] << "\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm retrieving files like this String[] files = assetFiles.list(EngagiaDroid); How can we know whether
When retrieving a lookup code value from a table, some folks do this... Dim
What is the Ruby idiomatic way for retrieving a single character from a string
Similar question as this one but for a Microsoft Environment. Email --> Exchange Server
for extracting special folder icons I'm using ExtractIconEx(Environment.SystemDirectory + \\shell32.dll,ncIconIndex, handlesIconLarge, handlesIconSmall, 1); Here
I am retrieving an XML string through a URL. My code works great, but
After retrieving search results from a UISearchBar, the results appear in my tableview correctly,
I'm retrieving results from mongo based on a geo query using the ruby driver.
i am retrieving data from guardian web service using c#. The answer i get
i am retrieving information from an excel sheet, i want to take the information

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.