Use fstream on opened file

Hello,
i need to know how to use fstream to edit opened file ( binary ) with openfile dialog.

I used this tutorial
http://www.daniweb.com/software-development/cpp/threads/159753/opening-a-filedialog

Thanks in advance

Thanks for fast response but i need more assistance

This is code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <windows.h>
#include <string.h>
#include <iostream>
#include <fstream>
using namespace std;
// Returns an empty string if dialog is canceled
string openfilename(char *filter = "Select file (*.bin)\0*.*\0", HWND owner = NULL) {
OPENFILENAME ofn;
char fileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = owner;
ofn.lpstrFilter = filter;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "bin";
string fileNameStr;
if ( GetOpenFileName(&ofn) )
fileNameStr = fileName;
return fileNameStr;
}
int main() {
cout << openfilename().c_str();
fstream openfilename;
openfilename.open("save.bin",fstream::in | fstream::out | fstream::binary);
openfilename.seekg(0x16);
openfilename.put(0xFF);
openfilename.seekg(0x4A);
openfilename.put(0x0F);
openfilename.seekg(0x4B);
openfilename.put(0x27);
openfilename.close();
 }


How to tell program to edit opened file an not save.bin?

Looks like istream isnt helping me or i dont understend something
fstream has put member that i need

Thanks in advance
On Line 26 you associate the stream 'openfilename' with the file 'save.bin' using the "open()" member function. If you want to work with a different file then change which one the stream is associated with.
1
2
fstream openfilename;
openfilename.open(openfilename().c_str(),fstream::in | fstream::out | fstream::binary);
thanks very much
it worked
had to remove line 24 to make it work....
cheers

solved
Topic archived. No new replies allowed.