帮助文件i / o [英] help with file i/o

查看:61
本文介绍了帮助文件i / o的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在尝试编写一个保存日志的程序,我基本上有3列会话时间,总时间和评论顺序


我想要做的是读入最后一行的总时间,并将其存储在3个变量hr,min,sec中,然后添加当前会话时间以获得新的总时间。


i试图使用StreamReader并且编译器是visual c ++ 2003

a日志文件中第一行的示例如下:

hey i am trying to write a program that saves logs and i have basically 3 columns session time,total time and comments in that order

what i want to do is read in the total time on the last line, and store it in 3 variables hr, min, sec then add the current session time to get teh new total time .

i was trying to use StreamReader and the compiler is visual c++ 2003

a sample of the first line in the log file is below:


00:00:04 --- 00:00:04 ---评论......
00 : 00 : 04 --- 00 : 00 : 04 --- Comments...



任何帮助将非常感谢,谢谢


哦,对不起如果这是在错误的论坛我新来的大声笑lol

any help will be much appreciated thanks

oh and sorry if this is in the wrong forum im new here lol

推荐答案




这很可能转移到C ++论坛。


但是无论如何......

您的问题是您不知道如何开始编写伪代码?

或者您是否在代码执行过程中遇到问题?


欢呼


this would most probably be shifted to the C++ forums.

But anyhows...
Is your issue that you do not know how to start coding your pseudo code?
or are you facing issues within the code execution?

cheers


我想我的代码有问题...这是我的第一个真正的Windows窗体项目...无论如何问题是我需要的东西会像C中的fscanf一样工作所以我可以读整数甚至数字一个字符串直到空格,然后我可以转换为int。


我自己清楚了吗?


i正在使用streamreader类但是Read()只读取一个char而ReadLine()在这里不适用... ReadBlock()似乎是更好的选择,但复杂的数据类型使它太混乱,难以实现。


i甚至认为将每个数字作为一个字母读取并转换为然后乘以10并在其后添加数字,例如48 =(4x10)+8但这似乎是太多的迂回方式了。
well i guess i am having problems with code... this is my first real windows forms project... anyways the problem is that i need something that will work like fscanf in C so that i can read in the integers or even the numbers as a string up to the whitespace which i can then convert to an int.

am i making myself clear?

i was using the streamreader class but Read() only reads a single char and ReadLine() isnt applicable here... ReadBlock() seems to be the better choice but the complicated data types makes it too confusing and hard to implement.

i was even thinkin abt reading each number as a letter and convert to in then multiply by 10 and add the number after it so for e.g 48 =(4x10)+8 but that seems like too long a roundabout way to do it.


你能读取文件了吗?


C ++应该等同于.Net有拆分

所以读取文件中的每一行,然后一旦你有最后一行..使用该行上的拆分,拆分---这样你就可以分成所有3个字段。


欢呼
have you been able to read the file?

C++ should have an equivalent of what .Net has "Split"
So read each line in your file, and then once you have the last line.. use the split on that line, splitting on "---" so that you can get all 3 fields in seperate strings.

cheers


这篇关于帮助文件i / o的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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