considering visual C++ compiler, Lets say I've got a file with whatever extension and it contains 100 bytes of data which are exactly the data that I want to initialize an array of char data type with a length of 100 characters with, Now apparently one way is to read those data out of file by using I/O file classes or APIs at run-time but what I want to know is that, is there any way using directives or something to tell the compiler I want to put that data in a right place in my application image files at compile time and compiler should go read those data out of that file?
views:
67answers:
3
+4
A:
- Write a program that reads the 100 byte data file and generates as output, a file, with c++ code/syntax for declaring an array with the 100 bytes in the file.
- Include this new generated file(inline) in your main c++ file.
- Call the c++ compiler on the main c++ file.
letronje
2010-09-18 19:27:28
This won't work--he says the file is raw data (not code)
egrunin
2010-09-18 20:48:30
That is because the question has been edited since I answered.
Dipstick
2010-09-18 21:36:38
@Dipstick_No, Edition didn't have anything to do with changing the core issue.
Pooria
2010-09-23 07:41:17
You didn't originally state that the data was in binary format. If it is then just convert it to comma separated hex ascii before hand then include that.
Dipstick
2010-09-24 06:13:13
@Dipstick_Actually I did and that's why others proposed solutions regarding the matter.
Pooria
2010-09-24 15:57:37
+2
A:
You do this with a resource in a Windows program. Right-click the project, Add, Resource, Import. Give the custom resource type a name. Edit the resource ID, if necessary. Get a pointer to the resource data at runtime with FindResource and LoadResource.
Hans Passant
2010-09-18 19:41:11
The resource compiler, yes. Not much examining going on, it just embeds the bytes.
Hans Passant
2010-09-18 19:59:23
You tell that still using a function like FindResource or LoadResource is required and that would be done at run-time, I meant a solution at compile-time.
Pooria
2010-09-23 07:28:00