使用c++将TXT文件转换为html文件
using c++ to convert a txt into html
我目前正在做一个项目,我读取一个文本文件,使其成为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
谢谢
在您的istream
中,技巧是将流中的char
与13
或10
(取决于您是LF (ascii=10, found on UNIX-like systems)
还是CRLF (ascii=13, ascii=10, found on Windows)
的换行符)进行比较。
例如,假设ch
是istream
(LF
)中最近的char
:
if(ch == 10)
// insert <br>
对于(CRLF
),给定ch1
是最新的,ch2
是第二最新的:
if(ch1 == 10 && ch2 == 13)
// insert <br>
13
和10
分别为回车和换行的值。
这就是它的全部。听起来你可以做剩下的了
相关文章:
- 将生成文件转换为 CMakeLists.txt等效项
- 如何将 UTF-8 文本从文件转换为某个可以迭代的容器,并检查每个符号是否为C++字母数字?
- 如何使用 CreateProcess 调用 tshark 将捕获文件转换为 txt
- 使用emscripten将c++文件转换为wasm时出错
- 将Qt qml文件转换为位图图像
- (对于C++)读取类型从文件转换为 2D 数组
- 使用向量将字符串从C 中的文件转换
- 编写一个 C++ 程序以将文本文件转换为 HTML 文件
- 如何在 C++ 中将矩阵市场文件转换为矩阵
- 是否可以将信息从XML文件转换为CPP
- 将 ASCII 文件转换为 C++ 的二进制格式
- 将生成文件转换为CMakeLists;无法加载共享库
- FlatBuffers:未支撑的工会向量错误将JSON文件转换为二进制文件
- 如何使用 qt 将 Linux 文本文件转换为 Windows 文本文件
- 如何将可执行文件转换为 C++ 文件以达到代码峰值
- 将windows软件中的未知数据库文件转换为MySqli数据库
- 如何将 .npy 文件转换为 .binaryproto
- 使用ICEBuilder将ICE文件转换为C++
- 将文件转换为字符串数组C++
- 在编译时将文本文件转换为字符串