copy a file

S

Severin Ecker

hi!

i'm trying to copy a file with the std::copy function but my problem is,
that whitespaces are discarded. could anyone tell me how i can just copy all
the characters that are in the source-file. thx.

std::istream_iterator<std::string> ins(in), eos;
std::eek:stream_iterator<std::string> outs(out);
std::copy(ins, eos, outs);

thanks,
sev
 
R

Ron Natalie

Severin Ecker said:
hi!

i'm trying to copy a file with the std::copy function but my problem is,
that whitespaces are discarded. could anyone tell me how i can just copy all
the characters that are in the source-file. thx.

std::istream_iterator<std::string> ins(in), eos;
std::eek:stream_iterator<std::string> outs(out);
std::copy(ins, eos, outs);
You can have the ostream_iterator output a separator if you give it a second
arg:
std::eek:stream_iterator<std::string> outs(out,'\n');

Do you really want to be doing formatted I/O?
If you want to literally copy the file, it's probably better to use use a loop of
read/write combintations (or getline at the worst).
 
T

Tanguy Fautré

Severin Ecker said:
hi!

i'm trying to copy a file with the std::copy function but my problem is,
that whitespaces are discarded. could anyone tell me how i can just copy all
the characters that are in the source-file. thx.

std::istream_iterator<std::string> ins(in), eos;
std::eek:stream_iterator<std::string> outs(out);
std::copy(ins, eos, outs);

thanks,
sev

std::ifstream In(SrcFilename, std::ios::binary);
std::eek:fsteam Out(DstFilename, std::ios::binary);

Out << In.rdbuf();

Voilà
This will make an exact copy of the input file.

Tanguy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top