需要阅读文件和其他内容的理论帮助
我想在理论部分请求一些帮助,所以磨那些齿轮,
我想将一个文件加载到我的程序中,它看起来像这样:
0,10,10#0,100,40...
好吧,我现在想做的是取出每个逗号分隔的数字并通过我的函数发送
void func(int, float, float);
主题标签意味着它是一个新块,因此它将像 func(0,10,10) 一样发送,之后它将发送 func(0,100,40) 等等。
我想检查每个字符,直到遇到“,”,然后将其放入向量中,然后继续直到遇到“#”。然后它会解雇我的函数(如 func(v[0],v[1],v[2]) ,然后一遍又一遍地做同样的事情,直到 EOF!
这是一个好方法吗?有更好的方法吗?想法?这些数字稍后也会变得非常大,所以我不知道我需要多少内存(因此向量)。或者我应该使用 3 个临时整数和浮点数,然后触发该函数并重新开始!
i would like to request some help on theory part, so grind those gears, here it comes
I want to load a file into my program, which looks something like this:
0,10,10#0,100,40...
Okay what i now want to do is to take out every comma separated number and send it through my function
void func( int, float, float );
The hashtag means it's a new block, so it would be sent like func(0,10,10) and after that it would send func(0,100,40) and so on.
I was thinking to check every char until i meet ',' and after that put it in a vector, and continue that until the '#' is met. Then it would fire away my function (like func(v[0],v[1],v[2]) and then just do the same thing over and over until EOF!
Is this a good way to go? Have any better ideas? Those numbers can also get very large later on, so i don't know how much memory i need (therefor the vector). Or should i just go with 3 temp ints and floats and then fire the function and start over!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
按照您的建议逐个字符并使用状态机是最快的方法。
然而,最简单的方法是首先用
#
分割,然后对每个结果字符串用,
分割。您可以使用 boost 库来执行字符串 split< /a>.
Going char by char and using a state machine like you suggested is the fastest way.
However the easiest way is first to split by the
#
and then for each result string split by,
.You can use boost library to do the string split.
非常简单、快速、容易。
Very simple, fast, and easy.
如果您确定文件以三个一组的第一个 int 开头
应该可以工作。 (我没有编译过,所以可能有错别字等)
If you're certain the file starts with the first int of a group of three
should work. (I haven't compiled it so there might be typos etc)