如何为输入文件构建解析器
我可以获得一些为输入文件构建解析器的指导吗?我几周来一直在寻求帮助,作业已经过期了,我只想知道如何做。
注释的代码是我尝试过的,但我感觉它比这更严重。我有一个文本文件,我想解析它以计算单词在文档中出现的次数。
Parser::Parser(string filename) {
//ifstream.open(filename);
// source (filename, fstream::in | fstream::out);
}
can i please get some guidance to constructing a parser for an input file, I've been looking for a help for weeks, the assignment is already past due, I would just like to know how to do it.
The commented code is what I've tried, but i have a feeling it is more serious than that. I have a text file and I want to parse it to count the number of times that words appear in the document.
Parser::Parser(string filename) {
//ifstream.open(filename);
// source (filename, fstream::in | fstream::out);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有一种感觉,你什么都没尝试过。所以我也会这样做。
Google 是你的朋友 。
I have a feeling you haven't tried a thing. So I am going to do the same.
Google is your friend.
读取单词:
注意:这是一个真实的单词 :-)
http://dictionary.reference.com/browse/floccinaucinihilipilification
To read a word:
Note: That is a real word :-)
http://dictionary.reference.com/browse/floccinaucinihilipilification
查看如何你用 C++ 从文件中读取一个单词吗? .最简单的方法是使用
ifstream
和operator>>
读取单个单词。然后,您可以使用诸如vector
(如上面的链接中所述)或map
之类的标准容器来记住实际计数。Take a look at the answers in How do you read a word in from a file in C++? . The easiest way is to use an
ifstream
andoperator>>
to read single words. You can then use a standard container likevector
(as mentioned in the link above) ormap<string, int>
to remember the actual count.