Including files into an executable at compile/link time

  • Thread starter Thread starter mezarashi
  • Start date Start date
  • Tags Tags
    files Time
AI Thread Summary
To include a large .txt data file within an executable in Visual C++ using MS Visual Studio 2005, the recommended approach is to statically initialize a character pointer with the file's content. This method allows the program to access the data without needing a separate file during distribution. While attempts to use HTML resources have been unsuccessful, directly embedding the text as a char* variable can effectively solve the issue. This approach simplifies distribution by consolidating the program and its required data into a single executable file.
mezarashi
Homework Helper
Messages
652
Reaction score
0
I have a program that opens a very large .txt data file. This data file remains unchanged, but is always required to run the program. What I want to do is include this .txt into the .exe so that when I distribute the program I don't need to distribute two files, but only one instead.

I'm using Visual C++ with MS Visual Studio 2005. I've played around with some of the resources, but to no avail. I tried adding it as an HTML resource and then loading the resource, but the pointer to this resource apparently is invalid whether I treat it as a string of character bytes or as a file pointer.

Any ideas? Thanks in advance.
 
Technology news on Phys.org
You should be able to make it a large statically initialized char* and stick it in your program.

e.g.

Code:
char* file = "stuff that's in the file";

- Warren
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top