我有以下代码,其中的splice
函数不起作用而且没有返回任何结果,我不知道为什么。请帮助。
主要思想是我需要从列表中取一个范围并将其添加到另一个空列表中。
#include <iostream>
#include <list>
#include <list>
#include <vector>
#include <stack>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <ctime>
#include <sys/time.h>
#include <iterator>
using namespace std;
int main() {
ifstream
reader("list.txt");
list < string > wholeSequenceVctr;
list < string > sequenceVctr;
list < string > subsequenceVctr (10);
string line;
if (reader.is_open()) {
while (getline(reader, line)) {
wholeSequenceVctr.push_back(line);
}
}// if
sequenceVctr.insert(sequenceVctr.begin(),
wholeSequenceVctr.begin(),
wholeSequenceVctr.end());
list < string >::iterator from=sequenceVctr.begin();
list < string >::iterator to=sequenceVctr.begin();
advance(from,2);
advance(to,4);
subsequenceVctr.splice(subsequenceVctr.begin(),
sequenceVctr,
from,
to);
// printing section
cout << "wholeSequenceVctr" << endl;
list < string >::iterator i;
for (i = wholeSequenceVctr.begin(); i != wholeSequenceVctr.end(); ++i)
cout << *i;
cout << endl << "sequenceVctr" << endl;
list < string >::iterator j;
for (j = sequenceVctr.begin(); j != sequenceVctr.end(); ++j)
cout << *j;
cout << endl << "SubsequenceVctr" << endl;
list < string >::iterator k;
for (k = subsequenceVctr.begin(); k != subsequenceVctr.end(); ++k)
cout << *k;
}
以下是list.txt
文件的示例:
CP52
CP74
CP24
CP404
CP3812
CP5069