如何在文件中找到特定单词周围的单词
How to find words around a particular word in a file
我的结果中有一个大文件。我想在这个文件中查找一个特定单词周围的单词。例如,如果我有一个这样的文件:我我会首页他们是会学校山姆是会来午餐
如何使用c++获取"going"前后的单词并将其保存在散列中
您可以一个字一个字地读取文件,始终保持N个字作为上下文。您可以将上下文存储在允许滚动上下文的std::deque
中
const int N = 10;
std::deque<std::string> words_before, words_after;
std::string current_word, w;
// prefetch words before and after
for (int i = 0; i < N; ++i) {
std::cin >> w;
words_before.push_back(w);
}
std::cin >> current_word;
for (int i = 0; i < N - 1; ++i) {
std::cin >> w;
words_after.push_back(w);
}
// now process the words and keep reading
while (std::cin >> w) {
words_after.push_back(w);
// save current_word with the words around words_before, words_after
words_before.pop_front();
words_before.push_back(current_word);
current_word = words_after.front();
words_after.pop_front();
}
相关文章:
- 文本文件中的单词链表
- 在指针的帮助下,文本文件中单词的频率
- 如何根据单词在文本中出现的概率输出单词
- 从字符串变量中逐字符读取单词
- 使用std::mt19937从字符串中返回一个随机单词
- 如何用for循环在c++中生成单词三角形
- 将数字转换为单词
- 使用if-else将数字转换为单词
- C++-字符串是否包含一个带有简单循环的单词
- 使用单词"not"作为C ++类的名称会导致VS2019错误
- 为什么这个程序返回最后一个单词而不是最长的单词?
- 3-3. 编写一个程序来计算每个不同单词在其输入中出现的次数
- C++为一串单词添加空格
- 在C++中查找(奇怪的)字符串中的单词
- 当字符串是某个单词时给出输出?
- 用句子从单词打印单词
- C :按行读取txt文件的读数,单词用单词读取,每行的单词不均匀
- 如何将文件复制到另一个文件中,但是用用户输入的单词替换单词
- 用给定的网格和单词交叉单词
- 移动字符串中的单词,单词之间使用空格作为分隔符