0

Duplicate of

Is there a function in c++ that does the same that the split function in C?

I wrote this code

std::string str[] =line.split(";");

But a call to split is not recognized.

Community
  • 1
  • 1
Evans Belloeil
  • 2,413
  • 7
  • 43
  • 76

3 Answers3

2

Looks like you need qt solution :

#include <QStringList>
//...

QStringList L = line.split( ";" , QString::SkipEmptyParts );
//                                 ^^^^^^^^^^^^^^optional
P0W
  • 46,614
  • 9
  • 72
  • 119
1

Yes, there is a split function. See: http://qt-project.org/doc/qt-4.8/qstring.html#split as reference.

sara
  • 3,824
  • 9
  • 43
  • 71
1

There is no such a standard function in C++. You can use the following approach.

#include <iostream>
#include <sstream>
#include <vector>
#include <string>

//,,,


std::istringstream is( line );
std::vector<std::string> v;

std::string item;
while ( std::getline( is, item, ';' ) ) v.push_back( item ); 
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335