I'm new to C++, and I need to code a program that will create a text file with a large amount of text (at least 75k worth). There can be no seperate resource files in the final app, just the single executable.
What's the best way to do this?
I'm new to C++, and I need to code a program that will create a text file with a large amount of text (at least 75k worth). There can be no seperate resource files in the final app, just the single executable.
What's the best way to do this?
? details ?
What do you need in this text file? Random Data? Data retrieved from another source? Created with an algorithm? No details = no helpful solutions.
Provide more insight into the problem, so that we may be better able to assist.
edit: 75k isnt really a "large" text file.
It's a fixed set of data. If there's a way, I can simply make it part of the source code. It doesn't need to be generated or supplied externally. I know what it is at the time of compilation. I just need the program to be able to generate it into a new text file.
So why not just zip the file in an SFX?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Because that's not the only thing the program will do. It's just the only thing I don't know how to do.
cout << "This is the first line of the text file" << endl;
Rinse and repeat - how is this hard?
A fairly decent code editor should be able to make short work of this.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You're the one that doesn't want to use an external file - otherwise it would be that easy.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Or one line of perl....
Code:$ cat t1.txt Lamarck was the first man whose conclusions on the subject excited much attention. This justly celebrated naturalist first published his views in 1801; he much enlarged them in 1809 in his "Philosophie Zoologique", and subsequently, 1815, in the Introduction to his "Hist. Nat. des Animaux sans Vertebres". In these works he up holds the doctrine that all species, including man, are descended from other species. He first did the eminent service of arousing attention to the probability of all change in the organic, as well as in the inorganic world, being the result of law, and not of miraculous interposition. Lamarck seems to have been chiefly led to his conclusion on the gradual change of species, by the difficulty of distinguishing species and varieties, by the almost perfect gradation of forms in certain groups, and by $ perl -n -e '{ chomp; s/\"/\\"/g; print "cout << \"" . $_ . "\" << endl;\n"; }' t1.txt cout << "Lamarck was the first man whose conclusions on the subject excited much" << endl; cout << "attention. This justly celebrated naturalist first published his views" << endl; cout << "in 1801; he much enlarged them in 1809 in his \"Philosophie Zoologique\"," << endl; cout << "and subsequently, 1815, in the Introduction to his \"Hist. Nat. des" << endl; cout << "Animaux sans Vertebres\". In these works he up holds the doctrine that" << endl; cout << "all species, including man, are descended from other species. He first" << endl; cout << "did the eminent service of arousing attention to the probability of" << endl; cout << "all change in the organic, as well as in the inorganic world, being the" << endl; cout << "result of law, and not of miraculous interposition. Lamarck seems" << endl; cout << "to have been chiefly led to his conclusion on the gradual change of" << endl; cout << "species, by the difficulty of distinguishing species and varieties," << endl; cout << "by the almost perfect gradation of forms in certain groups, and by" << endl;
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Whatever way you go, there is going to be some intermediate step between a simple text file, and something you can compile with a C++ compiler.
You can't simply do
and have it compile.Code:const char myTextFile[] = { #include "anyRawTextFile.txt" };
Now you can generate (in all sorts of ways) a file you can #include using the above method, but there is no standard way of doing this. Maybe a perl script as above, or maybe your compiler comes with some kind of "resource editor" which is used to attach "media data" (of all kinds) to an executable.
Eg
perl foo.pl anyRawTextFile.txt > anyRawTextFile.h
Then you can do
And you will have the text file compiled into the code as one big string.Code:const char myTextFile[] = { #include "anyRawTextFile.h" };
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Anything that would fit on one of those old a floppy disks can't really be called "large" any more.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Well, the problem is that you have not provided any details of exactly what you need.
What's going to be in the file?
Is it random text characters?
Stuff entered by users?
Stuff from another file?
Source code?
And yes it does matter.
There is no programmer on earth who can code a solution to a problem he doesn't understand.
In your case that could be "beginneritis"
In our case it's because you seem bent upon not telling us what you're doing.