我想要一個矢量文檔變量,將看起來像轉換一個文本文件導入的std ::矢量<string>
document[0] = "I"
document[1] = " "
document[2] = "want"
document[3] = " "
document[4] = "cake"
document[5] = "."
document[6] = "\n"
隨着文件在給定行「我要的蛋糕。\ n」個
我我不知道如何去做這件事,而我在分隔符上找到的所有東西都會擺脫空白或其他東西。
我有一個unordered_set的停用詞,我想從文件中刪除。我設置的方法將迭代一個向量,並且remove_if單詞在我的停用詞中。
目標是將文檔向量中的所有元素放入一個沒有停用詞的新文件中。
std::vector<string> MakeFileVector(string filename){
//Get the input from the file
std::ifstream input(filename.c_str());
std::vector<string> doc;
string line;
//For each line in the text File
for (line ; getline(input, line);)
{
//somehow split up each word/space/period/comma/newline char
//and add to the doc vector
//for each word/space/period/comma/newline char
doc.push_back(str)
}
return doc;
}
添加了一些更多解釋 – HunterH
如果'I'和'want'之間有2個空格,是否應該是'「I」,「」,「」,「想要」或什麼 –
不應該爲我的目的,它可以是「」,在一個字符串內有兩個空格 – HunterH