如何使用C ++文件对象修改文件 [英] How to modify a file using C++ file objects

查看:76
本文介绍了如何使用C ++文件对象修改文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向所有人致意,


我有以下文件,我需要用

数组的内容修改它


File1.txt


名称地点积分等级

Venkat,Newyork,100,A

杰克, LA,12,C

Heather,拉斯维加斯,190,B

Jay,Sanjose,199,A

John,Austin,1, D $ / $

int NewPoints = {23,1,100,181,100}

现在我需要使用C ++的文件对象编写程序(ifstream,ofstream)

这样它应该打开文件File1.txt并且应该修改点数部分下的值

和NewPoints中的值。

紧急请让我知道如何去做。

谢谢和问候,

Venkat

解决方案

听起来像家庭作业。

Venkat写道:

向所有人致意,

我有以下文件,我需要修改它内容 一个
阵列

File1.txt

名称位置积分等级
Venkat,Newyork,100,A
Jack,LA,12 ,C
Heather,拉斯维加斯,190,B
Jay,Sanjose,199,A
John,Austin,1,D

int NewPoints = {23, 1,100,181,100}

现在我需要使用C ++的文件对象(ifstream,ofstream)编写一个程序,这样它应该打开文件File1.txt并修改值
在NewPoints中出现的积分部分。

紧急请告诉我如何去做。

感谢和问候,
Venkat




Venkat写道:

我有以下文件和我需要用
数组的内容修改它

File1.txt

名称位置积分等级
Venkat,Newyork,100,A 希瑟,拉斯维加斯,190,B
Jay,Sanjose,199,A
John,Austin,1,D

int NewPoints = {23,1,100,181,100}

现在我需要使用C ++的文件对象(ifstream,
ofstream)编写一个程序,这样它应该打开文件File1.txt和应该修改点数部分下的值和NewPoints中的值。




首先,你必须创建一个新文件并复制大部分文件。旧的

到新文件的东西。然后删除旧文件并重命名新文件。

完成。


原因是硬盘驱动器用于模拟数千个文件/>
磁带驱动器,每个文件都被视为一个小磁带单元(

潜在的巨大容量!)。如您所知,您无法在

录音带或任何其他类型的录像带上添加'东西''。请注意,

练习中的最少记录从1到100。(你不能删除任何东西,但添加

参数可能更具说服力。)


在创建新文件时修改点文件。


我怀疑C ++语言的最新版本是否提供了什么?所有你需要的是b $ b,但是< cstdio>中有一些旧的,生锈的工具。将执行文件

重命名位。


" Nirmalya Ghosh Chowdhury" <纳克****** @ ngc.com>在消息中写道

新闻:3F ************** @ ngc.com ...

听起来像家庭作业。



您好Nirmalya,


感谢您的热烈评论。我真的笑你的评论

哈哈哈........

我想让我的问题变得简单,以便其他人容易

理解并回答它。


我的应用程序涉及编写一个dll,当lanched调用

file1.txt时它是一个CSV(逗号分隔值)文件并动态替换它的内容。


我知道使用ifstream读取和写入文件的过程

ofstream对象,但是想知道在

特定的地方编辑文件有什么出路。


据我所知新闻组是为了分享这些知识而且我对这个小组并不天真,我一直积极地为这个小组做出贡献

来自过去两年。


但要像这样坦诚的评论会阻止人们使用这个

组。

问候,

Venkat


Greetings to All,

I have the following file and i need to modify it with the contents of an
array

File1.txt

Name Location Points Grade
Venkat,Newyork,100,A
Jack,LA,12,C
Heather,Las Vegas,190,B
Jay,Sanjose,199,A
John,Austin,1,D

int NewPoints = {23,1,100,181,100}
Now i need to write a program using file objects of C++(ifstream, ofstream)
such that it should open the file File1.txt and should modify the values
under Points section with that present in NewPoints.
It is urgent please let me know how to go about it.
Thanks and Regards,
Venkat

解决方案

Sounds like homework.
Venkat wrote:

Greetings to All,

I have the following file and i need to modify it with the contents of an
array

File1.txt

Name Location Points Grade
Venkat,Newyork,100,A
Jack,LA,12,C
Heather,Las Vegas,190,B
Jay,Sanjose,199,A
John,Austin,1,D

int NewPoints = {23,1,100,181,100}
Now i need to write a program using file objects of C++(ifstream, ofstream)
such that it should open the file File1.txt and should modify the values
under Points section with that present in NewPoints.
It is urgent please let me know how to go about it.
Thanks and Regards,
Venkat




Venkat writes:

I have the following file and i need to modify it with the contents of an
array

File1.txt

Name Location Points Grade
Venkat,Newyork,100,A
Jack,LA,12,C
Heather,Las Vegas,190,B
Jay,Sanjose,199,A
John,Austin,1,D

int NewPoints = {23,1,100,181,100}
Now i need to write a program using file objects of C++(ifstream, ofstream) such that it should open the file File1.txt and should modify the values
under Points section with that present in NewPoints.



First of all, you will have to create a new file and copy most of the old
stuff to the new file. Then delete the old file and rename the new file.
Done.

The reason for this is that the hard drive is used to emulate thousands of
tape drives, each file is really treated as a tiny tape unit (with a
potentially huge capacity!). And as you know, you can not add ''stuff'' to an
audio tape or any other kind of tape. Note that the least record in your
exercise goes from 1 to 100. (You can''t remove stuff either, but the adding
argument is probably more persuasive.)

Modify the points file as the new file is being created.

I doubt if the latest whiz-bang version of the C++ language provides all you
need, but there are some old, rusty tools in <cstdio> which will do the file
renaming bit.


"Nirmalya Ghosh Chowdhury" <ng******@ngc.com> wrote in message
news:3F**************@ngc.com...

Sounds like homework.



Hi Nirmalya,

Thanks for a hilarious comment. Really i am getting laugh on your comment
ha ha ha........
I want to make my question simple so that it would be easy for others to
understand and answer it.

My application involves writing a dll which when lanched calls the
file1.txt in question it is a CSV(Comma Seperated Value) file and replaces
its contents dynammically.

I knew the procedure of reading and writing to a file using ifstream and
ofstream objects but was wondering is there any wayout to edit the file at a
particular place.

To my understanding this newsgroup is meant to share the knowledge and i
am no naive to this group, i had been actively contributing to this group
from the past 2 years.

But to be frank comments like this would refrain people from using this
group.
regards,
Venkat



这篇关于如何使用C ++文件对象修改文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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