我正在使用以下代码解析 html 文档:
ifstream myfile("file.html");
string line;
int m_lines;
char c;
while(getline(myfile,line)) {
if(line.empty()) {
m_lines++;
continue;
}
istringstream iss(line);
while(iss.good()) {
c = iss.get();
//my code here (not important for this question)
cout << c;
}
m_lines++;
}
输入文件(file.html)如下所示:
<p>Lorem ipsum <strong>haha</strong> gfadf.</p>
<img src="image.jpg" alt="alt" />
输出:
<p>Lorem ipsum golo gama<strong>haha</strong> gfadf.</p> <img src="image.jpg" alt="alt" />
^
^
^
如果输入文件中有新行,则打印一个空格字符。如何跳过或删除此字符?