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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:37:44+00:00 2026-06-05T15:37:44+00:00

Briefly, I am trying to write a routine that reads comma separated values from

  • 0

Briefly, I am trying to write a routine that reads comma separated values from a file into a stl vector. This works fine. The values in the csv file might also be in double quotes so I have handled this too by trimming them. However, there is one problem where the values between the quotes might also have commas in them which are not to be treated as delimiters.

If I have a file containing the line

"test1","te,st2","test3","test4"

My file routine reads this into a vector as

"test1"
"te
st2"
"test3"
"test4"

I wrote a routine which I just called PostProcessing. This would go through the vector and correct this problem. It would take each element and check of the first value was a quote. If so it would remove it. It would then look for another quote at the end of the string. If it found one it would just remove it and move onto the next item. If it didn’t find one, it would keep going through the vector merging all the following items together until it did find the next quote.

However, this works in merging “te and st2” together into element 2 (index 1) but when I try and erase the required element from the vector it must be failing as the resulting vector output is as follows:

test1
test2
st2"
test3
"test4"

Note also the last element has not been processed because I derement the size of the count but as the vector erase has failed the true count hasn’t actually changed.

The PostProcessing code is below. What am I doing wrong?

bool MyClass::PostProcessing()
{
bool bRet = false;

int nCount = m_vecFields.size();

for (int x = 0; x < nCount; x++)
{
    string sTemp = m_vecFields[x];

    if (sTemp[0] == '"')
    {
        sTemp.erase(0,1);

        if (sTemp[sTemp.size()-1] == '"')
        {
            sTemp.erase(sTemp.size()-1, 1);
            m_vecFields[x] = sTemp;
        }
        else
        {
            // find next double quote and merge these vector items
            int offset = 1;
            bool bFound = false;

            while (x+offset < nCount && !bFound)
            {
                sTemp = sTemp + m_vecFields[x+offset];

                if (sTemp[sTemp.size()-1] == '"')
                {
                    // found corresponding "
                    sTemp.erase(sTemp.size()-1,1);
                    bFound = true;
                }
                else
                {
                    offset++;
                }
            }

            if (bFound)
            {
                m_vecFields[x] = sTemp;

                // now remove required items from vector
                m_vecFields.erase(m_vecFields.begin()+x+1, m_vecFields.begin()+x+offset);

                nCount -= offset;
            }
        }
    }
}

return bRet;
}

Edit: I’ve spotted a couple of issues with the code which I will be correcting but they don’t affect the question being asked.

  • 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-05T15:37:47+00:00Added an answer on June 5, 2026 at 3:37 pm
    m_vecFields.erase(m_vecFields.begin()+x+1, m_vecFields.begin()+x+offset);
    

    This function takes a semi-closed interval, which means the “end” of the interval to erase should point one-past the last element to erase. In your case, it points to that element. Change the second argument to m_vecFields.begin()+x+offset+1.

    x += offset;
    

    Since you’ve just processed an item and deleted everything up to the next item, you shouldn’t skip offset items here. The x++ from the loop will do just fine.

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

Sidebar

Related Questions

i'm trying to do something that is described briefly on the next link: link
Briefly: How to parametrize .prj WKT file so that I can perform 7 point
I know that this question is repeated one. But no one could answer briefly
I've only been using SSIS briefly, but I find that my complaints are numerous.
Here's briefly what I'm trying to do. The user supplies me with a link
I'll briefly explain what I'm trying to do: I need to sort a set
To summarise briefly what I'm trying to do: I'm providing the facility for a
Am trying to send a mail to recipient from iPhone app without user's interaction.
I'm trying to build a application that allows the user to either A) enter
I'm trying to find a way to invoke an interactive command-line program so that

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.