S
sd2004
Could someone please tell me why the code below not compile ?
Thanks in advance for your help.
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void split (const string& s, char c){
vector<string> v;
string:: size_type i=0;
float data;
string:: size_type j=s.find(c);
while (j!=string::npos){
v.push_back(s.substr(i,j-i));
i = ++j;
j=s.find(c,j);
if (j==string::npos)
v.push_back(s.substr(i,s.length()));
}
vector<string>::iterator pos;
pos = find (v.begin(),v.end(),2);
cout << "pos: " <<*pos <<endl;
}
int main (){
double results;
char const delim = ';';
string s("id;2;address;4;5;6;7");
split (s,delim);
}
Thanks in advance for your help.
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void split (const string& s, char c){
vector<string> v;
string:: size_type i=0;
float data;
string:: size_type j=s.find(c);
while (j!=string::npos){
v.push_back(s.substr(i,j-i));
i = ++j;
j=s.find(c,j);
if (j==string::npos)
v.push_back(s.substr(i,s.length()));
}
vector<string>::iterator pos;
pos = find (v.begin(),v.end(),2);
cout << "pos: " <<*pos <<endl;
}
int main (){
double results;
char const delim = ';';
string s("id;2;address;4;5;6;7");
split (s,delim);
}