我在main()之外无法理解an的概念。我试图声明一个数组,然后将所有行都推回main中声明的矢量,然后将该数组传递给外部拆分矢量。我的问题是了解如何将从txt文件中读取的行传递到拆分向量以进行拆分,然后在main方法中将第四个逗号后的值返回到原始向量。
vector<string> split(const string& s, const string& delim) {
const bool keep_empty = true;
vector<string> result;
if (delim.empty()) {
result.push_back(s);
return result;
}
string::const_iterator substart = s.begin(), subend;
while (true) {
subend = search(substart, s.end(), delim.begin(), delim.end());
string temp(substart, subend);
if (keep_empty || !temp.empty()) {
result.push_back(temp);
}
if (subend == s.end()) {
break;
}
substart = subend + delim.size();
}
return result;
}
void binary(vector<string> &airPort);
void Linear_Search(vector<string> &airPort);
int main()
{
vector<string> airPort;
string s;
int counts = 0;
string inp;
string total;
string cat = "cat";
string a, b, c, d, e;
char bs;
ifstream file("airports.dat");
if (!file.is_open()) {
cout << "Filed to Open File!" << endl;
return 0;
}
while (getline(file, s))
{
istringstream ls(s);
airPort.push_back(s);
}
vector<string> airPort = split(",", s); //trying to pass the lines in
the airPort vector to be
split up
最后,我试图将其设置为仅用第四个逗号之后的值更新airPort向量的位置,因此程序的其余部分可能会使用该更新的向量。