从文件读取 [英] reading from a file

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

问题描述

您好,例如,我怎么能从c ++中的tex中读取带有ID号的学生列表?例如,将其视为文本文件...



2007100307,OGUZ,CEYLAN,cet
2005100700,HASAN,COSKUN,tt
2008400024,DUYGU,ALGAN,cmpe
2007101336,BETUL,ARI,cmpe
2006104564,ERCAN,AY,ee
2008400180,ERVIN,DOMAZET,man
2004102743,AHMET FAIK,BAK,cmpe
2007100631,EMRECAN,BATI,cee
2004104291,TURGAY,CAN,cet
2003104024,ERSIN,AYDIN,ee
2006104624,AHMET,AYDIN,cmpe
2008400033,HAKAN,DEMIR,男人
2007100625,ENES BAHADIR,DISBUDAK,男人
2003104471,HASAN,ELMAS,人
2007102347ESRA,ARSLAN,cmpe
2005100736,REMZI,ASCI,ee
2006102371,BULUT,DEMIR,ptw
2007100934,ISMAIL,ATKURT,ee

Hİ, how can ı read a student list with their id number from a tex in c++?for example;think that list in a text file...



2007100307, OGUZ ,CEYLAN , cet
2005100700, HASAN , COSKUN , tt
2008400024,DUYGU ,ALGAN , cmpe
2007101336, BETUL ,ARI ,cmpe
2006104564,ERCAN , AY , ee
2008400180, ERVIN ,DOMAZET,man
2004102743,AHMET FAIK, BAK , cmpe
2007100631, EMRECAN ,BATI ,cee
2004104291, TURGAY, CAN , cet
2003104024,ERSIN, AYDIN , ee
2006104624,AHMET , AYDIN , cmpe
2008400033, HAKAN , DEMIR , man
2007100625, ENES BAHADIR , DISBUDAK , man
2003104471,HASAN,ELMAS,man
2007102347ESRA ,ARSLAN ,cmpe
2005100736,REMZI ,ASCI ,ee
2006102371, BULUT ,DEMIR , ptw
2007100934,ISMAIL, ATKURT ,ee

推荐答案

做到这一点的最佳方法是编写一个iostreams扩展来读取您的类的实例.我敢肯定,我有一篇关于代码项目的文章,说明了如何完成此工作(尽管可能是WJD的文章,在这种情况下,它应该仍然可以搜索).

IOStream插入器和提取器 [
The best way to do this, is to write an iostreams extension that reads an instance of your class. I am certain I have an article on code project showing how that is done ( although it may have been a WJD article, in which case, it should still be googlable ).

IOStream Inserters And Extractors[^]

That''s it.


您可以从 scanf组开始 [^ ] ,以读取和解析输入行.或者,获取之一 [strtok [ ^ ].
You could start with the scanf group[^] of functions, to read and parse an input line. Aternatively one of the gets[^] group, and then do your own parsing, either manually or with strtok[^].


答案采用文章的形式.它确切地解释了它在做什么.我建议您首先不要在问题中张贴答案",而应根据需要编辑问题以添加详细信息.其次,如果您对C ++不够了解,无法阅读一篇介绍如何使用C ++的文章,那么也许您不具备执行此任务的能力?您可以只使用iostream零散读取数据,但是按照我发送的链接,我看不出有什么方法比正确地完成数据更容易.

据我所知,您已经被告知如何使用C(strtok等)以及如何使用C ++(iostreams). C ++绝对更好.但是,如果您仍然不知道如何开始,那么我将不得不问您为什么这样做?如果要上课,您应该与您的老师交谈,并告诉他们您完全迷路了.如果您是为了工作而做的,但是对C ++的了解不足,甚至看不到给出的答案,那么这有点可耻了.我怀疑这是一堂课.您的老师认为您知道该怎么做.他应该是你告诉你不能的第一个人.您还应该假设他知道如何使用Google,并且可以找到您的作业已经在线发布了.
The answer takes the form of an article. It explains exactly what it is that it is doing. I would suggest that you first, do not post ''answers'' to your question, instead edit your question to add details as required. Second, if you don''t know enough about C++ to read an article that explains how to use it, perhaps you''re not capable of this task ? You CAN just use iostreams to read the data in piecemeal, but I don''t see how that is any easier than doing it properly, as per the link I sent.

As far as I can see, you''ve been told how to do it with C ( strtok, etc ) and how to do it with C++ ( iostreams ). C++ is definitely better. But, if you still have no idea how to start, then I would have to ask why you''re doing this ? If it''s for a class, you should talk to your teacher and tell them you are utterly lost. If you''re doing it for work, but don''t know enough C++ to even see the answers you were given as a way to be able to start, then that''s a bit disgraceful. I''m suspecting this is a class. Your teacher assumes you know how to do this. He should be the first person you tell that you cannot. You should also assume he knows how to use google and can find where your assignment has been posted online.


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

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