PushBack (push_back()) elements of QStringList to vector<string>

user2754070

How can I access elements of QStringList in a vector<string> type. push_back doesn't work. inserting too needs another vector type only.

#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QStringList>
#include <vector>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
        QCoreApplication a(argc, argv);
        std::vector<string> vec;
        QString winter = "December, January, February";
        QString spring = "March, April, May";
        QString summer = "June, July, August";
        QString fall = "September, October, November";
        QStringList list;
        list << winter;
        list += spring;
        list.append(summer);
        list << fall;
        qDebug() << "The Spring months are: " << list[1] ;
        qDebug() << list.size();

        for(int i=0;i<list.size();i++)
        {
        //vec.push_back(list[i]);
        }
        exit(0);
        return a.exec();
}
drescherjm

I would do this:

foreach( QString str, list) {
  vec.push_back(str.toStdString());
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

string Vector push_back failing in class

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

Why can't I push_back to a vector of const elements?

From Dev

vector string push_back is not working in c++

From Dev

vector push_back in STL?

From Dev

Vector and push_back() behavior

From Dev

Unable to push_back to vector

From Dev

[ performance]--- string::operator+= vs. vector<char> push_back

From Dev

std::string in object being deleted during push_back to std::vector

From Dev

vector push_back zero into an empty vector

From Dev

push_back a vector of vectors into a vector

From Java

Insert or push_back to end of a std::vector?

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

vector::push_back and std::move

From Dev

Why are there two overloads for vector::push_back?

From Dev

garbage values for vector push_back

From Dev

push_back new element to vector

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

garbage values for vector push_back

From Dev

Vector push_back incredibly slow

From Dev

Vector push_back Array of doubles

From Dev

Push_back variadic function parameters into a vector?

From Dev

c++ push_back() a struct into a vector

From Dev

vector of reference wrapper, push_back failure?

From Dev

push_back a pointer to a vector of pointers

From Dev

Put integer in to string using pushback

From Dev

Put integer in to string using pushback

From Dev

How to push_back an integer to a string?