| game (22) | |
|
Dear Users and developers! I have two or three text files! I want to add them to single text file! say file1.txt, file2.txt, file3.txt file 1 2 3 4 file2 5 6 7 8 file3. 10 20 30 30 combined file 1 2 3 4 5 6 7 8 10 20 30 Any help!!!! With Best regards Game | |
|
|
|
| Darkmaster (494) | |
|
http://www.cplusplus.com/doc/tutorial/files/ just make sure you dont close the combined file, before you are done with all the output. | |
|
|
|
| SamuelAdams (321) | |
|
open dos prompt type file1.txt file2.txt file3.txt > outputfile.txt Either that or show us what you have so far | |
|
|
|
| game (22) | |
|
dear Samuel, I didn't get your idea! I am using c++, i have two text files (file1 and file2) I want to add them together using c++ code! That is my difficulty Regards | |
|
|
|
| JLBorges (1756) | |||
| |||
|
|
|||
| Imadatobanisa (647) | |
|
This is a method (There are many methods around) : Create two string variables (buffer) Use the function fread. Read both two files (means storing all results into two string variables (buffer)). Each file you should use a different buffer. Use the function fwrite, write all results into a single file... Other methods that I know : ReadFile - WriteFile ..... Ifstream - Ostream... (Take a google search if necessary) Hope this helps (see the example above) | |
|
Last edited on
|
|
| game (22) | |
|
Thank very much, this helps much! | |
|
|
|
| SamuelAdams (321) | |
|
Hi Game, I know this is a C++ forum but you said nothing about programming in your post or what you needed to do, read a file, open a file, close a file, write.... People make such silly post on here, I was trying to be funny too :) I know it failed to be funny... :( Normally we expect you to post your code of what you have tried, since there are a lot of students on here wanting someone to do their homework. The simple way would be open a file check to make sure it is open open the output file check to make sure it is open read line write line continue until done go to next file I Like what JLBorges posted, I'll have to play withthat, I have not seen rdbuf() used before. If that works it looks much more condensed. | |
|
|
|
| game (22) | |
|
Dear Samuel, Thank for your comment! I am using a Libraries form Opencascade. I do not think necessary to post this coding here. One: It is to long to post from start, and second: Very different from c++ syntax. That is why! Thank you very much for the answer, some how busy with other staff now! I will post the possible answer soon! Regards | |
|
|
|
| game (22) | |||
|
Dear ALL, Does anybody tried what JLBorges (1363) proposed: I tried as follow: But it combine the first two files, not both of them! Anybody tried?
In combinedfile, there is only files from file1 and file2, not file3 and file4. What is wrong, is it for two files only? Regards Game | |||
|
|
|||
| JLBorges (1756) | |||||
|
> In combinedfile, there is only files from file1 and file2, not file3 and file4. > What is wrong, is it for two files only? Make sure that file3 and file4 are in a good state. Something like this perhaps:
And then
| |||||
|
|
|||||