问题描述
对于在我的C ++类中到期的作业,我被指示创建一个C ++代码,该代码从包含此信息的.dat文件中读取相同的格式:
For an assignment due in my C++ class I am instructed to create a C++ code that reads from a .dat file containing this info in the same format:
T-Shirt:
15
Jeans:
60
Jacket:
80
Sweatshirt:
30
Hoodie:
40
Socks:
15
Discount:
10
我想知道是否有人可以向我解释如何编写只读取数值而不是字符值的代码。非常感谢。
我尝试过:
我在谷歌和其他论坛上四处看看,我找不到我想要的东西。我的教授没有给我们任何关于这方面的信息,我已经多次阅读了指定的章节。
I was wondering if anyone could explain to me how to write a code that will only read the number values rather than the character values. It would be much appreciated.
What I have tried:
I've looked around on google and other forums and I can't quite find what I'm looking for. My professor didn't give us any information on this and I've read the assigned chapters a couple of times.
推荐答案
我想知道是否有人可以向我解释如何编写一个只读取数值而不是字符值的代码。非常感谢。
I was wondering if anyone could explain to me how to write a code that will only read the number values rather than the character values. It would be much appreciated.
1)作为一个整体或第1行读取文件。
2)每行检查数字或不是
3)如果是数字,那就做你需要的。
1) read the file either as a whole or lines 1 by 1.
2) for each line check if number or not
3) if number, do what you need to.
这篇关于如何只用C ++中的输入文件读取数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!