|
-
February 23rd, 2009, 09:55 AM
#1
How to Search for a Piece of Text in Binary File by Using fstream - C/C++?
I got a binary file, i opened the file. I need to look for this "255.255.255.255", and then replace it with the user newly inserted IP...
I know there is something called seekp(), but it needs me to determine where to point in the file. I do not know yet. Once i find the spot 255.255... I will have to write from the iso::beg, right?
1. I can go through the file line by line by using getline()...Is there another solution?
2. Assume i went through the file & i found 255.255.255.255, to overwrite it do i t have to start from 2, or before 2? I guess ios::beg has to be involved in someway.
3.
Code:
ofstream file1;
file1.open("OutputTrial1.txt", ios::binary );
file1.write(temp,sizeof(temp));
file1.close();
In this line file1.open("OutputTrial1.txt", ios::binary ); OutputTrial1.txt is not binary, so how come we specified it as a binary in parameter two?
Regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|