convert char** (c string array) to std::string[]

This is a discussion on convert char** (c string array) to std::string[] within the C++ Programming forums, part of the General Programming Boards category; Hello is there fast way to convert c char** to std::string[] array without loop the char** ?...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    58

    convert char** (c string array) to std::string[]

    Hello
    is there fast way to convert c char** to std::string[] array without loop the char** ?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    Nope.

    Well there's probably some cute one-liner statement you could use from the STL, but that would only hide the loop from your code, and it wouldn't make it noticeably any faster.

    Why are you trying to optimise something which only happens once anyway?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Salem is right on both accounts. A possible one-liner:

    Code:
    std::vector<std::string> strings(cstrings, cstrings + num_cstrings);
    This uses the pointer to c-strings as iterator, which can be used for the vector constructor.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Replies: 4
    Last Post: 03-03-2006, 01:11 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21