Embed data in a C++ program
You can use objcopy to bind the contents of the file to a symbol your program can use. See, for instance, here for more information.
How to permanently store information using C program?
People have done this all kinds of ways. In order from best to worst (in my opinion):
- Use a registry or equivalent. That's what it's there for.
- Use an environment variable. IMO this is error prone and may not really be what you want.
- Store a file on your user's computer. Easy to do and simple.
- Store a file on a server and read/write to the server via the network. Annoying that you have to use the network, but OK.
- Modify your own binary on disk. This is fun as a learning experience, but generally inadvisable in production code. Still it can be done sometimes especially using an installer.
- Spawn a background process that "never" dies. This is strictly worse than using a file.
When embedding CLIPS into C Language, what function can used to modify the fact from C program
Section 4.4 of the Advanced Programming Guide, http://clipsrules.sourceforge.net/OnlineDocs.html, has a list of functions that can be used on facts. The fact-set queries and distributed actions in section 12.9.12 of the Basic Programming Guide are also useful for retrieving and manipulating facts from a C program. For example, you could use the following function call to retrieve all person deftemplate facts where the value in the age slot was greater than 18:
DATA_OBJECT result;
Eval("(find-all-facts ((?p person)) (> ?p:age 18))",&result);
How to embed a file into an executable?
A portable way is to define a function like
typedef unsigned char Byte;
Byte const* pngFileData()
{
static Byte const data =
{
// Byte data generated by a helper program.
};
return data;
}
Then all you have to do is to write a little helper program that reads the PNG file as binary and generates the C++ curly braces initializer text. Edit: @awoodland has pointed out in comment to the question, that ImageMagick has such a little helper program…
Of course, for a Windows-specific program, instead use the ordinary Windows resource scheme.
Cheers & hth.,
Related Topics
Explicit Return Type of Lambda
Can Branches with Undefined Behavior Be Assumed Unreachable and Optimized as Dead Code
Is There a Standard Way of Moving a Range into a Vector
Linux C++: How to Profile Time Wasted Due to Cache Misses
Enum VS Constexpr for Actual Static Constants Inside Classes
C++ Best Way to Get Integer Division and Remainder
Why Use !! When Converting Int to Bool
Pass by Pointer & Pass by Reference
Does Try-Catch Block Decrease Performance
Why Sizeof Int Is Wrong, While Sizeof(Int) Is Right
Do I Have to Bind a Udp Socket in My Client Program to Receive Data? (I Always Get Wsaeinval)
Boost::Property_Tree Xml Pretty Printing
C++ Ifstream Error Using String as Opening File Path
Restrict Variadic Template Arguments