我們實現乙個簡單的文字查詢程式。我們的程式允許使用者在乙個給定檔案中查詢單詞,查詢結果是單詞在檔案**現的次數及所在行的列表。如果乙個單詞在一行**現多次,此行只列出一次。
#include#include1.txt#include
#include
#include
#include
#include
#include
using
namespace
std;
//主要完成將輸入檔案轉換為map形式
map> runqueries(ifstream &infile)
++lines;
}return
map_word;
}int
main()
cout
<
elements occurs
"times
"<
auto ss=iset.begin();
while(ss!=iset.end())
return0;
}
alice emma has long執行結果如下:flowing red hair.
her daddy says when the wind blows
through her hair, it looks almost alive,
like a fiery bird
inflight.
a beautiful fiery bird, he tells her,
magical but untamed.
"daddy, shush, there is no such thing,
"she tells him, at the same time wanting
him to tell her more.
shyly, she asks,
"i mean, daddy, is there?
"alice emma has
long
flowing red hair.
her daddy says when the wind blows
through her hair, it looks almost alive,
like a fiery bird
inflight.
a beautiful fiery bird, he tells her,
magical but untamed.
"daddy, shush, there is no such thing,
"she tells him, at the same time wanting
him to tell her more.
shyly, she asks,
"i mean, daddy, is there?
"alice emma has
long
flowing red hair.
her daddy says when the wind blows
through her hair, it looks almost alive,
like a fiery bird
inflight.
a beautiful fiery bird, he tells her,
magical but untamed.
"daddy, shush, there is no such thing,
"she tells him, at the same time wanting
him to tell her more.
shyly, she asks,
"i mean, daddy, is there?
"
c 容器實現文字查詢程式
vs2010編譯通過 缺點 無大小寫區分,沒有剔除標點符號 search.h pragma once include include include include include include include include include using namespace std class c...
c 學習筆記 文字查詢程式
需求 1.開啟需要查詢的文字檔案,將檔案的內容以行的方式讀出並儲存起來,需要記錄行號和對應的文字。2.把每一行以單詞進行拆分,把每個單詞及該單詞出現的行號記錄起來,乙個單詞可能出現在多行。3.處理單詞查詢功能,返回指定單詞出現在文字中的所有行號集合。4.遍歷得出的行號集合,根據行號從1中返回對應下標...
c prime 課後題 文字查詢程式
根據書裡的提示寫的 1.使用vector儲存文字 2.用map儲存 的關鍵字,和關鍵字所屬行號。3.使用ifstream,istringstream,ostream來解析文字,輸出結果 是完全自己寫的實現,和書裡的結構不太一樣,但處理查詢的思路是相同,畢竟提示已經給到這個地步了。標頭檔案 inclu...