1
我目前正在研究一個項目,在那裏我讀取一個文本文件,使其成爲html的正文代碼。 問題是每當有一個輸入/換行符時,我必須在其中輸入「
」。 而且......我不確定我是否能確定是否有新線。使用C++將一個txt轉換爲html
這裏是我到目前爲止的代碼:
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
istream findParagraph(istream& is, string& word) {
//if there's a new line here I need to make sure I add "<br \>"
//into is; then send it back to main
}
int main(int argc, char* argv[]) {
argv[1] = "The Republic, by Plato.txt";
ifstream infile(argv[1]);
char ch = 0;
ofstream out("title.html");
out << "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">" << endl
<< "<head>" << endl
<< "<meta http - equiv = \"Content-Type\" content = \"text/html; charset=UTF-8\" />" << endl
<< "<title>" << argv[1] << "</title>" << endl
<< "</head>" << endl
<< "<body>" << endl;
typedef map<string, unsigned> dictionary_type;
dictionary_type words;
string word;
while (findParagraph(infile, word))
++words[word];
out << "</body>" << endl << "</html>";
} //end main
感謝
嘿藍色的冰。感謝您的回覆。 我只有一個小問題。如果用戶使用Windows並且文件中的文本文件的ASCII = 13,該怎麼辦? – Jarvis
實際文字'ASCII = 13'?或者值'13'?如果它是值'13',那麼它是回車。 –
我的意思是ASCII值13。 什麼是回車? – Jarvis