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,303
  • 6
  • 40
  • 74

3 Answers3

2

Looks like you need qt solution :

#include <QStringList>
//...

QStringList L = line.split( ";" , QString::SkipEmptyParts );
//                                 ^^^^^^^^^^^^^^optional
P0W
  • 44,365
  • 8
  • 69
  • 114
1

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

sara
  • 3,724
  • 9
  • 40
  • 70
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
  • 265,791
  • 20
  • 170
  • 303