如何阅读带有符号"/"的生日和“:"从.txt文件? [英] How to read a birthday with symbols "/" and ":" from a .txt file?

查看:51
本文介绍了如何阅读带有符号"/"的生日和“:"从.txt文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写c ++ prgram,必须从 .txt 文件中读取一些数据.格式如下:"姓名性别DD/MM/YYYY HH:MM:SS "

I am writing a c++ prgram and have to read some data from a .txt file.the format looks like the following: "name gender DD/MM/YYYY HH:MM:SS"

我知道如何读取 .txt 文件并逐个cin单词,但是我不知道如何处理符号"/"或"<代码>:".
我必须比较两个人的年龄.

I know how to read a .txt file and cin the words one by one, but i dont know how to deal with the symbols "/" or ":".
I have to compare the ages of two person.

请帮助!

推荐答案

除了使用 sscanf 的最简单方法之外,例如

Aside from the easiest way with sscanf, like Jerry describes, it's also possible with iostreams. Just read the data you want from the file, until you hit a seperator, and discard that one into a dummy char:

char dummy;
myfile >> first_name >> last_name >> day >> dummy >> month >> dummy ... // and so on.

这篇关于如何阅读带有符号"/"的生日和“:"从.txt文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆