每次遇到要用fstream讀檔案時
都覺得很麻煩
尤其是string的find和substr
每次Google每次忘記
所以這次要把它記下來!!
fstream query_file;
query_file.open("OOVquery.syl.txt", fstream::in);
while(!query_file.eof()) {
char buffer[256];
query_file.getline(buffer, 256);
string eachLine = string(buffer);
text.append(" ");
int pos = 0;
int pos2 = 0;
while((pos2 = text.find(" ", pos)) != string::npos) {
string subsyl = text.substr(pos, pos2 - pos);
//這裡記得要+1,不然會一直找到第一個" "
pos = pos2+1;
}
}
沒有留言:
張貼留言