如何通过c ++在.dat文件中查找文本 [英] How to find text in .dat file by c++
本文介绍了如何通过c ++在.dat文件中查找文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!我有一个类似的.dat文件:
id产品价格
1 nokia 200
2 samsung 150
3 iphone 300
...
n ..... ..
当我用c ++选择id时如何找到产品和价格
请给我一个提示!谢谢!
解决方案
读取每行文本并使用其中一个tokenizer函数,例如 strtok
[ ^ ],分割每个字符串。
ref this
< a href = http://www.cplusplus.com/reference/cstring/strtok/ > http://www.cplusplus。 com / reference / cstring / strtok / < / a > [< a href = http://www.cplusplus.com/reference/cstring/strtok/ target = _ blank < span class =code-attribute> title = 新窗口 > ^ < / a > ]
读取每一行并将其放入地图中:
键是id列,值是对< string,int>。
然后,根据id查询值
Hi! I have a .dat file like that:
id product price
1 nokia 200
2 samsung 150
3 iphone 300
...
n ..... ..
How to find product and price when I select id by c++
Please give me a tip! thanks!
解决方案
Read each line of text and use one of the tokenizer functions, such as strtok
[^], to split each string.
ref this <a href="http://www.cplusplus.com/reference/cstring/strtok/">http://www.cplusplus.com/reference/cstring/strtok/</a>[<a href="http://www.cplusplus.com/reference/cstring/strtok/" target="_blank" title="New Window">^</a>]
Read the each line and put it in a map:
the key is id column, the value is the pair<string,int>.
then, according the id to query the value.
这篇关于如何通过c ++在.dat文件中查找文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文