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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:20:57+00:00 2026-05-23T12:20:57+00:00

I need to have a function in C++/CLI which do the link between a

  • 0

I need to have a function in C++/CLI which do the link between a C++ native std::list<std::string> and a string[] in C# to do something like that with my WinForm :

    ComboBox1.Items.AddRange(installs);

installs is the string[].

Do you have an idea? How can I do this? C++/CLI programming is hard without Intellisense. 🙁

What do you think about this?

Native C++ .cpp

std::list<std::string>* Get_Liste_place_de_marche(void)
{
    list<string>* liste_place_de_marche = new list<string>;
    liste_place_de_marche->push_back("CAC 40");
    liste_place_de_marche->push_back("DAX");
    return liste_place_de_marche;
}

And I need to code this function using the last code to the top :

C++/CLI .cpp called in my Winform with C#

array<System::String^>^ NativeMethod::Get_Liste_place_de_marche(void)
{
    typedef std::list<std::string>::const_iterator iter_t;

    std::list<std::string> const* list = new std::list<std::string>;
    list = ::Get_Liste_place_de_marche();

    array<System::String^>^ ret = gcnew array<System::String^>(list->size());
    int j = 0;

    for (iter_t i = list->begin(); i != list->end(); ++i)
        ret[j++] = gcnew System::String(i->c_str());

    return ret;
}

It should work? Because I have many errors…

  • 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-23T12:20:58+00:00Added an answer on May 23, 2026 at 12:20 pm

    The following should do the job:

    array<System::String^>^ ArrayFromList(std::list<std::string> const& list) {
        typedef std::list<std::string>::const_iterator iter_t;
    
        array<System::String^>^ ret = gcnew array<System::String^>(list.size());
        int j = 0;
    
        for (iter_t i = list.begin(); i != list.end(); ++i)
            ret[j++] = gcnew System::String(i->c_str());
    
        return ret;
    }
    

    I would try to keep this more general, though. For instance, it’s customary in C++ to work on iterator ranges instead of containers. Furthermore, the above only works on (zero-terminated) strings. Very similar code will be needed to convert other object collections. It might make sense to abstract the object conversion away.

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

Sidebar

Related Questions

I have a function where I need to do something to a string. I
I need to have a function that sort of acts like mysql resources sometimes
I have a function that i need to call on iframe mousemove(). But i
I have need for a function pointer that takes two arguments and returns a
I have a function where I get a list of ids, and I need
in delphi7 i have a function that i need to return a array as
I have two classes that each need an instance of each other to function.
I need to marshal an array of String^ to call a unmanaged function that
I need to have a function which takes a 2D array and generates random
I'm wondering because I need to have have a function that is disgustingly fast

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.