It is as simple as adding two binary data streams from the files together and outputting the result into the new file. If the files are bigger you might want to save yourself creating the third data stream and just append the two into the combined file.

Note that some file formats have headers and footers which means unless your file contains only raw data you may not get the result you expect.

It basically creates two strings, two input files, two text streams, inputs the text streams from the files into the strings, and finally outputs the strings into the third text stream which is the output file.

To anyone more experienced, I am curious if there is a way to directly copy raw data from disk without using the dynamically allocated char[] to read in the two files. Thanks![/quote]

Yes, there is. It is never a good idea to just allocate a block of memory the size of a file you don't know. What if the file is 2GB, the other file is big as well? You'll run out of memory in no time flat. Instead, you read the file block by block, perhaps in blocks of 4KB or so. Note that Qt has a QByteArray class you can use for this purpose, instead of a raw char array.

Also, note that there really isn't a need to read in the first file at all. Simply copy the first file to the new file first (the OS can handle that more efficiently than you can), and then open the copy in append mode and add whatever is in the secons file to it.

Last, for croussou:

Note that if you concatenate binary files like this, the file is not likely to be valid any more. For instance, if you add two mp3 files together like this, the result will not be one mp3 file that just has both original songs, and combining two jpg images will not result in one bigger image that has both. There is no generic way to concatenate files in a meaningful way.

Yes that was what I had in mind last night but it was kind of late so I went with the "simpler" solution. BTW I already warned him about merging files that contain format headers, this is applicable ONLY for raw data.

For specific formats the concatenation must also be format specific, you must know how to parse that file, read in header tags and process them and only merge the raw data.

I was also thinking about pre-allocating the output file to the size of both inputs so that fragmentation can be avoided.

Since we are now talking BIG files, it would be wise to abort the operation early on in case there is not enough free space on disk, not merge the files all the way to 90% and fail just then, when time has been waster and the entire disk has been filled, which may have other negative implications.

Well, specific file formats typically have a header, which defines properties, such as bitrate, color depth, resolution, after which follows the raw data.

For example, if you want to join two images together, you have to read the resolution and color depth, figure out how you want to compose the two input images into the output image, do some conversion if the data is in a different format and so on.

Aha, okay I get it now thanks. What about .zip files, that's what I am mostly interested about...

Can I zip a file through my application? For example, there is a button for file creation, then another one checking if the file really exists and then a button called add to archive, where I put the file in question, in a .7z, .rar archive.

[quote author="croussou" date="1329984083"]Aha, okay I get it now thanks. What about .zip files, that's what I am mostly interested about...

Can I zip a file through my application? For example, there is a button for file creation, then another one checking if the file really exists and then a button called add to archive, where I put the file in question, in a .7z, .rar archive.[/quote]

No, it will not work with archives such as zip or 7z. Archives have headers as well. Those headers describe which files or folders are in the archive, and where their data can be found inside the file.

[quote author="ddriver" date="1329984668"]You have no option but use the archive format API to merge two archives together.[/quote]

I don't want to merge :) I just want to save a file that I read from my application in a .zip format. For example a text file, I want to be able to add it in an archive on the desktop through the app that is.

[quote author="croussou" date="1329984584"]It was mostly a general question, if there is any way for an application to provide files in an archive :)
Not about concatenation itself...just the zipping process.[/quote]
Grmbl!
Then please, why do you only say that now? Why do you send us down a different road, trying to answer the question you asked instead of the question you have? Please spend a bit more time formulating your actual question in the future; describe what you want to achieve, not how you think you might achieve it. That will make us spend our time more efficiently.

You cannot expect others to write all your code for you, you have to learn it for yourself, and it does take time. Even if your get all the code snippets from others, without the proper skills you will not be able to put them together in a working program. Rome wasn't built overnight you know ;)

A final word of advice, don't think, not even for a moment, that you will be able to avoid the hard work of digging through the documentation, all the examples you see cover at best the very basics, learning to find what you need in the DOC is MANDATORY if you really intend to become a programmer.