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

  • Home
  • SEARCH
  • 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 6979959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:57:09+00:00 2026-05-27T17:57:09+00:00

This is a followup to my previous question. Parsing file names from a character

  • 0

This is a followup to my previous question.

Parsing file names from a character array

The answer was relevant but I am still having trouble. When the strings are split, I can’t seem to get them to output correctly to my error log either as a string or cstring and to be honest, I don’t completely understand how his answer works. So does anyone have a further explanation of the answer the gentleman provided. How would I split the character array into a larger number of strings rather than just writing them all out. This was the answer.

std::istringstream iss(the_array);
std::string f1, f2, f3, f4;
iss >> f1 >> f2 >> f3 >> f4;

Imagine I have 30 different strings. Surely, I can’t write f1, f2….f30.

Any advice on how to do this?

  • 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-27T17:57:10+00:00Added an answer on May 27, 2026 at 5:57 pm

    You can even avoid explicit for loops and try a way that is more natural to modern C++ if you will.

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <sstream>
    #include <iterator>
    
    int main()
    {
       // Your files are here, separated by 3 spaces for example.
       std::string s("picture1.bmp   file2.txt   random.wtf   dance.png");
    
       // The stringstream will do the dirty work and deal with the spaces.
       std::istringstream iss(s);
    
       // Your filenames will be put into this vector.
       std::vector<std::string> v;
    
       // Copy every filename to a vector.
       std::copy(std::istream_iterator<std::string>(iss),
        std::istream_iterator<std::string>(),
        std::back_inserter(v));
    
       // They are now in the vector, print them or do whatever you want with them!
       for(int i = 0; i < v.size(); ++i)
        std::cout << v[i] << "\n";
    }
    

    This is the obvious way of dealing with a scenario like “I have 30 different strings”. Store them all somewhere, an std::vector is probably suitable, depending on what you might want to do with the filenames. This way you don’t need to give every string a name (f1, f2, …), you can just refer to them by indices of the vector if needed, for example.

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

Sidebar

Related Questions

this is actually a followup from a previous question but it contains different information
This is a followup from a previous question: When to use PDO prepared queries.
A followup to this previous question: Current code: var query = from b in
This is followup question from my previous question Toggle button inside accordion using jquery
This is a followup question from a previous question, which is hopefully a little
This is a followup of a previous question I had. I got the very
This is a followup on the question: ASP.NET next/previous buttons to display single row
This is a follow up from my previous question I have this code basically
This is a follow-up to my previous question . I still find it very
This is a follow up to my previous question . My code is still

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.