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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:26:54+00:00 2026-06-15T20:26:54+00:00

I have a string: 1,a,2,b,3,c etc I want to convert it to a pair

  • 0

I have a string:

1,a,2,b,3,c etc

I want to convert it to a pair vector:

std::vector<std::pair<int, QString> > myVector;

With 1 being the int and a being the string, 2 being the next int and b being the next string etc.

Thanks

  • 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-15T20:26:55+00:00Added an answer on June 15, 2026 at 8:26 pm
    int main()
    {
      QString foo = "1,a,2,b,3,c";
      QStringList splits = foo.split(',');
      assert(splits.size() % 2 == 0); // check if even
      qDebug() << splits;
    
      std::vector< std::pair<int, QString> > vs;
      for(QStringList::const_iterator it = splits.begin(); 
          it != splits.end(); ++it) { 
        bool ok;
        QStringList::const_iterator tmp = it;
        ++it;
    
        vs.push_back(std::make_pair(tmp->toInt(&ok, 10), *it));
        assert(ok); // check if conversion worked
      }
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have strings like 84, 03 etc. that I want to convert to Date
I have a query string: a=1&b=2&c[1]=3&c[2]=4 etc… I want a NSDictionary where a =>
I have a case class case class Doc(title:String, ....) which I want to convert
I have string on the format $0Option one$1$Option two$2$Option three (etc) that I want
I have a string as &euro; . I want to convert it to hex
I have come across some Base64 conversion functions in .net(FromBase64.string etc). What i want
I have a string with many fractions like 1/2, 1/4 etc. I want to
I have a string like so: option_alpha=value option_beta=some other value option_gamma=X ...etc. I'm using
I have a string that ends with _[a number] e.g. _1 _12 etc etc.
I have an input string such as x=y|a=b|c=10 etc which gets converted to dynamic

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.