在读取包含空白表格的 .txt 文件时需要帮助吗?
考虑这个 -
“ID_REF”“GSM887”“GSM888”“GSM889”“GSM890”“GSM891”
10 -.427 -3.841 .312 0
11 -.939 -1 -.024
现在,当我遍历包含许多此类条目的整个文本文件时如何识别空白。我需要找到每列的平均值,那么如何跳过空白(空)值。如果有人能告诉我一种用 C++ 实现的方法,那将会很有帮助。
Consider this -
"ID_REF" "GSM887" "GSM888" "GSM889" "GSM890" "GSM891"
10 -.427 -3.841 .312 0
11 -.939 -1 -.024
Now how to recognize blanks when I am traversing through whole text file containing many such entries. I need to find mean of every column so how do I skip blank (null) values. It will be helpful if someone can tell me a way to do it in C++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果唯一的分隔符是任意数量的空格,那么您不能,因为那么
与检查字符代码相同
,并且希望您有 /t 或其中的任何制表符而不是所有空格。
啊,既然你有制表符,你的数据实际上看起来像这样
你现在需要做的就是将分隔字符串解析为数组。
像这样的 C:从分隔源字符串创建字符串数组< /a>
甚至更好,橡胶靴所说的
if the only delemiter is an arbitrary number of spaces, then you can't, because then
is the same as
check the character codes and hopefully you have /t or whatever a tab character is in there instead of just all spaces.
Ah, since you have tabs, your data actually looks like this
What you need to do now is called parsing a delimted string to an array.
Something like this C: creating array of strings from delimited source string
or even better, what rubber boots said
我同意@Matt 的观点。您可以将txt中的所有空格替换为逗号(将其转换为excel中的csv文件),然后就可以了。
I agree with @Matt. You can replace all the spaces with comma in txt (switch it to a csv file in excel) and you will be good to go.