주석 처리 된 버전과 설명되지 않은 버전의 코드로 시도했습니다.
string separator1(""); //dont let quoted arguments escape themselves
string separator2(",\n"); //split on comma and newline
string separator3("\"\'"); //let it have quoted arguments
escaped_list_separator<char> els(separator1, separator2, separator4);
tokenizer<escaped_list_separator<char>> tok(str);//, els);
for (tokenizer<escaped_list_separator<char>>::iterator beg = tok.begin();beg!= tok.end(); ++beg) {
next = *beg;
boost::trim(next);
cout << counter << " " << next << endl;
counter++;
}
다음 형식의 파일을 분리합니다.
12345, Test Test, Test
98765, Test2 test2, Test2
이것은 출력입니다
0 12345
1 Test Test
2 Test
98765
3 Test2 test2
4 Test2
문제가 어디에 있는지 잘 모르겠지만 달성해야 할 것은 98765 이전에 숫자 3을 갖는 것입니다.
개행 구분 기호를 잊었습니다. string separator2(",\n");
#include <iostream>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
using namespace std;
using namespace boost;
int main() {
string str = "TEst,hola\nhola";
string separator1(""); //dont let quoted arguments escape themselves
string separator2(",\n"); //split on comma and newline
string separator3("\""); //let it have quoted arguments
escaped_list_separator<char> els(separator1, separator2, separator3);
tokenizer<escaped_list_separator<char>> tok(str, els);
int counter = 0, current_siding = 0, wagon_pos = 0, cur_vector_pos = 0;
string next;
for (tokenizer<escaped_list_separator<char>>::iterator beg = tok.begin(); beg != tok.end(); ++beg) {
next = *beg;
boost::trim(next);
cout << counter << " " << next << endl;
counter++;
}
return 0;
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다