- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: C++ Filestream
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-08-2006 09:17 PM
тАО10-08-2006 09:17 PM
C++ Filestream
Which wll take compare two file lets say Input1 and Input2.
It wll delete contents of Input1 from Input2 files.
Can somebody suggest me a better idea of doing it, using fstream
Input1 File
Hello how are you I am fine.
C++ world.
People in This forum is great.
Input 2 file
I am doing fine
Wishing u all the best.
Hello how are you I am fine.
C++ world.
People in This forum is great.
Thanks for this program
When i run binary the contents of the file Input2 should be like
Input2 file
I am doing fine
Wishing u all the best.
Thanks for this program
- Tags:
- fstream
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2006 10:12 AM
тАО10-09-2006 10:12 AM
Re: C++ Filestream
In general, if the files aren't sorted, you'll need to keep file1 in memory so you don't need to re-read file1 for each line in file2. You would then sort file1 and when reading file2, use a binary search to see if in file1.
Alternately, you can add a new field to file2, containing the original order, sort it and file1 and then read the records, removing duplicates. Then re-sort file2, and remove the extra field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2006 10:23 PM
тАО10-09-2006 10:23 PM
Re: C++ Filestream
// here is the code
#include
#include
#include
fstream fp1;
fstream fp2;
fstream temp;
boolean line_to_print=true;
string str_line_fp1;
string str_line_fp2;
fp1.open ("Input1_File", fstream::out);
fp2.open ("Input2_File", fstream::out);
temp.open ("tempFile", fstream::in);
while (fp2.good()) {
fp2 >> str_line_fp2;
while (fp1.good()) {
fp1 >> str_line_fp1;
// check if linefile2 is in file1
if (str_line_fp2 == str_line_fp1)
line_to_print=false;
} //end wihle fp1
if (line_to_print == true) {
temp << str_line_fp2;
temp.flush();
}
line_to_print=true;
} //end wihle fp2
rename ("tempFile", "Input2_File");
// end
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-09-2006 10:33 PM
тАО10-09-2006 10:33 PM
Re: C++ Filestream
Ciauz ;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2006 10:49 AM
тАО10-10-2006 10:49 AM
Re: C++ Filestream
Several problems with your fragment. You are using fstream vs stdio. :-)
You open each file in the wrong mode. You should NOT be calling flush, instead insert a '\n'. Replace boolean by bool. You need to call getline vs the string extracter. And you should be calling pubseekoff and clear to rewind fp1.
See attached.