Reputation:
I'm new to WIN32 programming. I followed up a tutorial series and tried to include it to my code. I got the error FILE was not declared in this scope. Seeing this in the video it seems that it is a type. But it isn't recognised here.
void write_file(char *path) {
FILE *file;
file = fopen(path,"wb");
int _size = GetWindowTextLength(TextBox);
char *data = new char [_size+1];
GetWindowText(TextBox,data,_size+1);
fwrite(data,_size+1,file);
}
void save_file(HWND hwnd) {
OPENFILENAME ofn;
char file_name[100];
ZeroMemory(&ofn,sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = file_name;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = 100;
ofn.lpstrFilter = "All Files\0*.*";
ofn.nFilterIndex = 1;
GetSaveFileName(&ofn);
write_file(ofn.lpstrFile);
}
Upvotes: 0
Views: 6428
Reputation: 100
Hi fopen
is a function from C I/O standard library (stdio.h).
If you would use that function, in your C++ program, you must include that library #include <cstdio>
.
But in the title you wrote C++, so in this case you can use iostream or fstream like
#include <iostream>
#include <fstream>
Read more here: fopen, stdio.h, cstdio, fstream, iostream.
Good luck!
Upvotes: -1
Reputation: 881633
The FILE
structure is in the cstdio
header file for C++. You could also use stdio.h
but that's mostly for compatibility with C code.
That means you'll need something like this in your file before you attempt to use it:
#include <cstdio>
However, that's the legacy C stuff for C++. It works but it's not really the C++ way. If you really want to learn C++ programming, you may want to steer clear of that and use streams instead. Look into the fstream
header.
Upvotes: 2