高效的文本文件复制 [英] Efficient Text File Copy

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

问题描述

大家好,


我想要做的是将一个简单的纯文本文件复制到另一个文件,但是省略重复项目。


我想这样做的方法,包括将所有项目复制到一个

数组中,然后循环遍历该数组寻找重复项,<删除它们,然后写入另一个文件。


对我来说,这似乎是一个非常漫长的方式,而且我

不知道所需数组的初始大小。


有人能建议一种有效的方法吗?


谢谢

Mick

Hi everyone,

What I am wanting to do, is to copy, a simple plain text file, to
another file, but omitting duplicate items.

The way I thought of doing this, involved copying all the items into a
array, and then looping through that array looking for duplicates,
removing them, and then writing to another file.

This seems a very long and drawn out way of doing this to me, and also I
do not know the initial size of the array required will be.

Could anyone suggest a effective efficient way of doing this?

Thanks
Mick

推荐答案



物化 <毫安********** @ privacy.net>在消息中写道

news:bv ************ @ ID-220437.news.uni-berlin.de ...

|大家好,

|

|我想要做的是将一个简单的纯文本文件复制到

|另一个文件,但省略重复的项目。

|

|我想这样做的方法,包括将所有项目复制到

|数组,然后循环遍历该数组寻找重复项,

|删除它们,然后写入另一个文件。

|

|对我来说,这似乎是一个非常漫长而漫长的方式,而且我也是b $ b |不知道所需数组的初始大小将是。

|

|任何人都可以建议一种有效的方法吗?


这取决于,因为有几种不同的方式可以接近这个。例如:

std :: set<> ;, std :: map<> ;, std :: vector<> ;,std :: unique()

是所有这些都可以让你想出一个算法。


你能告诉我们文件中的项目是什么吗?


你能告诉我们几行文件格式吗?

以及新文件的格式应该是什么样的?


干杯。 />
Chris Val

"Materialised" <ma**********@privacy.net> wrote in message
news:bv************@ID-220437.news.uni-berlin.de...
| Hi everyone,
|
| What I am wanting to do, is to copy, a simple plain text file, to
| another file, but omitting duplicate items.
|
| The way I thought of doing this, involved copying all the items into a
| array, and then looping through that array looking for duplicates,
| removing them, and then writing to another file.
|
| This seems a very long and drawn out way of doing this to me, and also I
| do not know the initial size of the array required will be.
|
| Could anyone suggest a effective efficient way of doing this?

That depends, because there are a few different ways
that one could approach this. For example:
std::set<>, std::map<>, std::vector<>, std::unique()
are all available for you to come up with an algorithm.

Can you tell us what constitutes an ''item'' in the file ?

Can you show us a few lines of the file format ?,
and what the format of the new file should look like ?

Cheers.
Chris Val


Chris(Val)写道:
Chris ( Val ) wrote:
" Materialized" <毫安********** @ privacy.net>在消息中写道
新闻:bv ************ @ ID-220437.news.uni-berlin.de ...
|大家好,
|
|我想要做的是将一个简单的纯文本文件复制到
|另一个文件,但省略重复的项目。
|
|我想这样做的方法,包括将所有项目复制到
|数组,然后循环遍历该数组寻找重复项,
|删除它们,然后写入另一个文件。
|
|对我来说,这似乎是一个非常漫长而漫长的方式,而且我也是如此不知道所需阵列的初始大小将是。
|
|任何人都可以建议一种有效的方法吗?

这取决于,因为有一些不同的方式可以让人接近这一点。例如:
std :: set<> ;, std :: map<> ;, std :: vector<> ;,std :: unique()
都可以提供给你一个算法。

你能告诉我们文件中项目的构成吗?

你能告诉我们几行文件格式吗?和>新文件的格式应该是什么样的?

干杯。
Chris Val
"Materialised" <ma**********@privacy.net> wrote in message
news:bv************@ID-220437.news.uni-berlin.de...
| Hi everyone,
|
| What I am wanting to do, is to copy, a simple plain text file, to
| another file, but omitting duplicate items.
|
| The way I thought of doing this, involved copying all the items into a
| array, and then looping through that array looking for duplicates,
| removing them, and then writing to another file.
|
| This seems a very long and drawn out way of doing this to me, and also I
| do not know the initial size of the array required will be.
|
| Could anyone suggest a effective efficient way of doing this?

That depends, because there are a few different ways
that one could approach this. For example:
std::set<>, std::map<>, std::vector<>, std::unique()
are all available for you to come up with an algorithm.

Can you tell us what constitutes an ''item'' in the file ?

Can you show us a few lines of the file format ?,
and what the format of the new file should look like ?

Cheers.
Chris Val




他说的是什么。另外有用的还有关于

记录顺序的信息:是否必须保存,是否排序?



What he said. Also helpful would be information about the order of the
records: must it be preserved, and are they sorted?


Chris (Val)写道:
Chris ( Val ) wrote:
" Materialized" <毫安********** @ privacy.net>在消息中写道
新闻:bv ************ @ ID-220437.news.uni-berlin.de ...
|大家好,
|
|我想要做的是将一个简单的纯文本文件复制到
|另一个文件,但省略重复的项目。
|
|我想这样做的方法,包括将所有项目复制到
|数组,然后循环遍历该数组寻找重复项,
|删除它们,然后写入另一个文件。
|
|对我来说,这似乎是一个非常漫长而漫长的方式,而且我也是如此不知道所需阵列的初始大小将是。
|
|任何人都可以建议一种有效的方法吗?

这取决于,因为有一些不同的方式可以让人接近这一点。例如:
std :: set<> ;, std :: map<> ;, std :: vector<> ;,std :: unique()
都可以提供给你一个算法。

你能告诉我们文件中项目的构成吗?

你能告诉我们几行文件格式吗?和>新文件的格式应该是什么样的?

干杯。
Chris Val
"Materialised" <ma**********@privacy.net> wrote in message
news:bv************@ID-220437.news.uni-berlin.de...
| Hi everyone,
|
| What I am wanting to do, is to copy, a simple plain text file, to
| another file, but omitting duplicate items.
|
| The way I thought of doing this, involved copying all the items into a
| array, and then looping through that array looking for duplicates,
| removing them, and then writing to another file.
|
| This seems a very long and drawn out way of doing this to me, and also I
| do not know the initial size of the array required will be.
|
| Could anyone suggest a effective efficient way of doing this?

That depends, because there are a few different ways
that one could approach this. For example:
std::set<>, std::map<>, std::vector<>, std::unique()
are all available for you to come up with an algorithm.

Can you tell us what constitutes an ''item'' in the file ?

Can you show us a few lines of the file format ?,
and what the format of the new file should look like ?

Cheers.
Chris Val



文件很简单一个项目列表,它可以是任何东西,让我们只说

这个例子它是一个购物清单,它将是格式


eggs

牛奶

面包

胡萝卜

果酱

...

.....

......等


对于物品的顺序也没有要求,因为程序将

最后调用system()调用。


The file is simply a list of items, it could be anything, lets just say
for this example its a shopping list, it would be in the format

eggs
milk
bread
carrots
Jam
...
.....
...... etc

There is also no requirement on the order of items, as the program will
make a system() call to sort at the end.


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

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