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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:14:32+00:00 2026-06-07T19:14:32+00:00

I am parsing an array of text that come from C-only interface and where

  • 0

I am parsing an array of text that come from “C-only” interface and where each string may have an arbitrary amount of values that may, isolatedly, be parsed by a “istream::operator >>()“.

For example, one of the parsers is for a custom IPv4 class:

std::istream &  operator >>( std::istream& stream, IPv4 &var )

The implementation is quite obvious.

Now suppose an input like:

const char *string_array[] =
{
    "192.168.0.1, 192.168.0.32,    192.168.0.40",
    "169.254.3.18, 169.254.3.19, 169.254.3.20, 169.254.3.21",
    "10.0.92.100",
    "10.0.0.101,    10.0.0.102,    10.0.0.103   ,  10.0.0.104 , 10.0.0.110  ",
};

I’d like to find an elegant way to put all of the parsed values in an array so that I can send it to “C-only” functions.

The naive way would be first contatening all of the strings (const char *) with a stringstream and then loop over this stream with my operator >>.

        std::stringstream   ss;
        IPv4 ip;
        std::vector< IPv4 > ip_vector;

         for ( int c = 0; c < count; ++c )
                        ss << string_array[ c ] << ", ";

         while ( ss.good( ) )
         {
                        ss >> ip;
                    ip_vector.push_back( ip );
         }

It seems not that wise to me, but I can’t figure out how to make this smarter.

Note also: Boost is not an option for this solution.

  • 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-07T19:14:34+00:00Added an answer on June 7, 2026 at 7:14 pm

    std::copy() and std::back_inserter is surely the way out.
    I’d stick, though with the for loop for iterating through the strings instead of concatenating everything in a stringstream, as suggested by @ephemient:

    std::vector< IPv4 > ip_vector;
    
    for ( unsigned c = 0; c < count; ++c )
    {
        std::stringstream   ss( string_array[ c ] );
    
        std::copy( std::istream_iterator< IPv4 >( ss ), std::istream_iterator< IPv4 >( ),
                    std::back_inserter( ip_vector ) );
    }
    

    This way you make clear you are transforming all the strings.
    You also have to construct 3 std::stringstream objects, but won’t have to relocate memory for concatenating strings.

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

Sidebar

Related Questions

I have a little script that replace some text, that come from a xml
I am parsing text output from a disk array that lists information about LUN
I am parsing an arbitrary length byte array that is going to be passed
I'm trying to grab the value of an array that I got from parsing
I have stored data in an array from XML Parsing. In the array I
there is a xml document that i'm parsing to array.. how can i access
I have an array of strings. The array was created by parsing a long
I am parsing a text file, and when I come across the word .word
Ok so I have a text file that will change regularly that I need
I have a link from that link: http://api.maxxiscentral.com/maxxiscentral/GetTyrePatterns from this link i want to

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.