C++编程思想第2卷第3章第9题怎么做??

desolator888 2014-04-14 11:45:55
思考了很久,不会做!!求解!
谁有第2卷参考答案的可以给份吗?
...全文
261 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
desolator888 2014-04-15
  • 打赏
  • 举报
回复
这个题蛮复杂的:源CPP,作用是消除一个文件中的标签,例如 一个文件中的内容是 <sda>dad</sd>sda <sdaf sdd>dsf<sdsd><sddsd sds >sdds 结果会显示 dadsda dsf sdds 下面的源程序看懂就得好久 #include <cassert> #include <cmath> #include <cstddef> #include <fstream> #include <iostream> #include <string> using namespace std; string& stripHTMLTags(string& s) { static bool inTag = false; bool done = false; while(!done) { if(inTag) { // The previous line started an HTML tag // but didn't finish. Must search for '>'. size_t rightPos = s.find('>'); if(rightPos != string::npos) { inTag = false; s.erase(0, rightPos + 1); } else { done = true; s.erase(); } } else { // Look for start of tag: size_t leftPos = s.find('<'); if(leftPos != string::npos) { // See if tag close is in this line: size_t rightPos = s.find('>'); if(rightPos == string::npos) { inTag = done = true; s.erase(leftPos); } else s.erase(leftPos, rightPos - leftPos + 1); } else done = true; } } return s; } int main(int argc, char* argv[]) { ifstream in(argv[1]); string s; while(getline(in, s)) if(!stripHTMLTags(s).empty()) cout << s << endl; } ///:~ 题目是 Modify HTMLStripper.cpp so that when it encounters a tag, it displays the tag’s name, then displays the file’s contents between the tag and the file’s ending tag. Assume no nesting of tags, and that all tags have ending tags (denoted with </TAGNAME>). 大致就是说 <body>sdd </body>dsafkl<head>dss</head> 要能显示 body: ssdd head: dss
wulathink 2014-04-14
  • 打赏
  • 举报
回复
木有但是可以拿出来讨论下啊

65,208

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧