C++初心者です。
string型の文字を任意の文字で区切る関数を作成しています。
ex) "abc/def" → "abc" "def"
以下のサイトを参考に下のような関数を作成しましたがコンパイルエラーが発生します。
http://vivi.dyndns.org/tech/cpp/string.html
どこが悪いのかご教授お願いできたらと思います。
よろしくお願いいたします。
自作プログラム
#include <iostream>
#include <string>
#include <vector>
//名前空間 自作関数はすべてmfという名前空間に入れることとする
namespace mf{
std::vector<std::string> split();
}
std::vector<std::string> split(const std::string str, char sep){
/*
strをsepで区切ったあとそれらをvector型配列で返す関数
std::vector<データ型>でデータ型のvectorを作成できる
*/
//string型ベクトルを定義
std::vector<std::string> v;
std::string::iterator first, last;
//最初の文字を取得
//std::string::iterator first = str.begin(); //autoはコンパイル時に自動で型を推論してくれる firstはイテレータ
first=str.begin();
while (first != str.end()){ //テキスト内が空になるまでループ
//std::string::iterator last = first;
last = first;
while (last != str.end() && *last != sep){
++last; //イテレータを進める
}
v.push_back(std::string(first, last));
if (last != str.end()){
++last; //分割文字の次へ
}
first = last;
}
return v;
}