2017-10-17 75 views
-1

文本文件的輸入格式如下,其中5是需要考慮的行數,1是第一個最頻繁的詞,第8個最頻繁的詞。我的問題是如何將這些數字讀入變量?我想從文本文件中讀取多行文本,並使用C++顯示每個單詞的頻率。

輸入文本文件:

5 1 8 

the classical latin alphabet also known as the roman alphabet is a writing system which evolved 

from the cumaean version of the greek alphabet the cumaean script was descended from the 

phoenician alphabet the cumaean alphabet was adopted and modified by the etruscans who 

ruled early rome the etruscan alphabet was in turn adopted and further modified by the 

ancient romans to write the latin language 
+1

重要的是要知道您要使用哪種語言。 http://idownvotedbecau.se/noresearch/ – tilz0R

+0

在問題標題中,語言是C++,如上所述。 –

+0

爲什麼C語言被標記? – tilz0R

回答

0

我可能會創建一個std::map<string, int>,並增加值爲每個字每次找到的文本詞。對於每個單詞,請檢查map中是否存在該鍵的值,如果不存在,請將其賦值爲1,否則只需將該值增加1。

相關問題