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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:50:30+00:00 2026-05-15T18:50:30+00:00

We have: std::string string_array[2]; string_array[0] = some data; string_array[1] = some more data; char*

  • 0

We have:

 std::string string_array[2];

 string_array[0] = "some data";

 string_array[1] = "some more data";

 char* cstring_array[2];

What is the most efficient way to copy data from string_array to cstring_array? Or pass string_array to the function, needed “const char* cstring_array[]“?

  • 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-15T18:50:30+00:00Added an answer on May 15, 2026 at 6:50 pm

    A function that takes a char const * is only written to accept a single string at a time, not an array of strings. To pass an std::string to such a function, just call the function with your_string.c_str() as the parameter.

    Edit: for a function that takes an array of strings, the obvious choice (at least to me) would be to write a minimal front-end that lets you pass a vector<std::string>:

    // The pre-existing function we want to call.
    void func(char const *strings[], size_t num) { 
        for (size_t i=0;i<num; i++)
            std::cout << strings[i] << "\n";
    }
    
    // our overload that takes a vector<string>:
    void func(std::vector<std::string> const &strings) { 
        std::vector<char const *> proxies(strings.size());
    
        for (int i=0; i<proxies.size(); i++)
            proxies[i] = strings[i].c_str();
        func(&proxies[0], proxies.size());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a char array which contains some value . I want to copy
Possible Duplicate: std::vector<std::string> to char* array I have to call a c function that
I have some C+ arrays that I have built as follows: std:array<const char *,
let's say I have std::map< std::string, std::string > m_someMap as a private member variable
I have typedef std::string OrderID; I would like to overload the operator ++ for
I have a std::map<std::string, HANDLE> SampleMap which stores HANDLE objects as value. After the
I have a std::map<std::string, myClass*> myMap then I am inserting like follow: if(!myKey.empty()) {
I have a std::vector<std::string> m_vPaths; I iterate over this vector and call ::DeleteFile(strPath) as
I have a simple question. I have a long std::string that I want to
In my current setup, I have a typedef std::function<void (MyClass&, std::vector<std::string>) MyFunction; std::map<std::string, MyFunction>

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.