Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus batch bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming gpu hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
another c++ question...

Reply  
Thread Tools
redivivus's Avatar
Senior Member with 1,464 posts.
 
Join Date: Mar 2006
Experience: 8th hindu reincarnation -- Praise Allah
19-Sep-2006, 09:39 PM #1
another c++ question...
I have not much clue what a .h file is, but my understanding is that they are used to contain classes? Is that the only purpose?

I am wondering how the best method would be to store a large amout of data for the program. I could just store it as a txt file and the program could read it, or i could make my main cpp file like 300 pages long, or...?

Could i do something like store the data (its a string...) in another file and load #include that file at the start?
__________________
Knowing others is wisdom;
Knowing the self is enlightenment.
Mastering others requires force;
Mastering the self needs strength.
~ Lao Tzu

If the rest of them can survive only by destroying us, then why should we wish them to survive?
~ Ayn Rand
redivivus's Avatar
Senior Member with 1,464 posts.
 
Join Date: Mar 2006
Experience: 8th hindu reincarnation -- Praise Allah
20-Sep-2006, 01:09 AM #2
What i tried was putting the whole string in:

const string wordlist = "... 190000 words later...";

When i try to open the cpp file in Dev C++ or compile it (assuming it opens), it only works after trying like 5 times. It gives errors after i added the wordlist.

=\ Better way to do it?
__________________
Knowing others is wisdom;
Knowing the self is enlightenment.
Mastering others requires force;
Mastering the self needs strength.
~ Lao Tzu

If the rest of them can survive only by destroying us, then why should we wish them to survive?
~ Ayn Rand
Shadow2531's Avatar
Senior Member with 2,640 posts.
 
Join Date: Apr 2001
20-Sep-2006, 05:55 AM #3
Quote:
Originally Posted by redivivus
I have not much clue what a .h file is
http://forums.techguy.org/developmen...-question.html
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
20-Sep-2006, 10:02 AM #4
Well, you CAN put data in a header file. It's not considered good practice.

Large amounts of data are generally best put in a data file and read during program execution.

If you do put long strings in program code, remember that chunks of a string can be concatenated thus:

char *str = "this is chunk 1 " "this is chunk2 "
"this is chunk 3" ;
redivivus's Avatar
Senior Member with 1,464 posts.
 
Join Date: Mar 2006
Experience: 8th hindu reincarnation -- Praise Allah
20-Sep-2006, 03:48 PM #5
Okay...

Il be a little more specific.

I want to store lots of data, and it will not all be used by the program execution. Infact, only 1/5 of it will ever be used at a time depending on which selection the user declares.

Someone suggested "stacks" which im going to look into, but if you were designing a program how would you go about storing this data? I also dont really want it all stored in a raw text file. =\

The way it is right now i just declared:

const string data = " ....................................... ";

When i try to open this will the compiler it gives an error. :-\ HOWEVER, the program does work if i can get it to compile. Better method?
__________________
Knowing others is wisdom;
Knowing the self is enlightenment.
Mastering others requires force;
Mastering the self needs strength.
~ Lao Tzu

If the rest of them can survive only by destroying us, then why should we wish them to survive?
~ Ayn Rand
Shadow2531's Avatar
Senior Member with 2,640 posts.
 
Join Date: Apr 2001
20-Sep-2006, 04:56 PM #6
What error does it give you?

Doing const string("very large string"); should compile and work as long as you have the mem.

How is the word list set up and how is it supposed to be used exactly?
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
20-Sep-2006, 05:26 PM #7
Quote:
Originally Posted by redivivus
Okay...

Il be a little more specific.

I want to store lots of data, and it will not all be used by the program execution. Infact, only 1/5 of it will ever be used at a time depending on which selection the user declares.

Someone suggested "stacks" which im going to look into, but if you were designing a program how would you go about storing this data? I also dont really want it all stored in a raw text file. =\

The way it is right now i just declared:

const string data = " ....................................... ";

When i try to open this will the compiler it gives an error. :-\ HOWEVER, the program does work if i can get it to compile. Better method?
The best way to store data really depends on how you'll be using the data. You haven't given us many clues. And we can't tell what your problem is without knowing why compilation fails...
redivivus's Avatar
Senior Member with 1,464 posts.
 
Join Date: Mar 2006
Experience: 8th hindu reincarnation -- Praise Allah
20-Sep-2006, 06:07 PM #8
Okay i will just post the whole thing for you i guess?

I am using Dev C++ to compile (and edit) the code. Not sure if either of you have/use it...

When i take out this majorly long string, i can do anything fine.
When this string is present, however, i get an error on opening the file. I choose not to terminate the program. Then to compile, i HAVE TO USE "Compile and Run" (compile itself causes the program to freeze) and every odd time it compiles, while it usually gives the exact same error as when i open the file.

Here is the error(s)... (goes to open file):




I will upload the code so far for you... try compiling with your compiler. As you can see there is a really long string.

Note: Had to split into several rar files since TechGuy set the size limit 56kb too low.


!! EDIT !! There is 1 error in that code which is 2 sets of "" around the data string.
Attached Files
File Type: rar backupmain.part01.rar (195.3 KB, 8 views)
File Type: rar backupmain.part02.rar (195.3 KB, 10 views)
File Type: rar backupmain.part03.rar (65.9 KB, 9 views)
__________________
Knowing others is wisdom;
Knowing the self is enlightenment.
Mastering others requires force;
Mastering the self needs strength.
~ Lao Tzu

If the rest of them can survive only by destroying us, then why should we wish them to survive?
~ Ayn Rand
redivivus's Avatar
Senior Member with 1,464 posts.
 
Join Date: Mar 2006
Experience: 8th hindu reincarnation -- Praise Allah
20-Sep-2006, 07:22 PM #9
I have tried putting all the data into a txt file and just reading it. It works... Figured maybe there was some type of like 'built in txt file' that might be able to be built into the exe, but this will have to work.

Thanks for the help all.
__________________
Knowing others is wisdom;
Knowing the self is enlightenment.
Mastering others requires force;
Mastering the self needs strength.
~ Lao Tzu

If the rest of them can survive only by destroying us, then why should we wish them to survive?
~ Ayn Rand
Shadow2531's Avatar
Senior Member with 2,640 posts.
 
Join Date: Apr 2001
21-Sep-2006, 08:15 AM #10
I checked the wordlist string from your main file ( after fixing the quotes ) and it's 1,763,167 bytes or so.

Code:
#include <iostream>
#include <string>
using namespace std;

int main() {
    const string wordlist("word0 word1 word2 etc.");
    cout << wordlist << endl;
}
That compiles fine with your word list with Mingw (The same compiler that the DevC++ IDE uses. ). It only uses 4MB of memory, so it shouldn't be a big deal to store the string in your program. Of course, you might want to use exceptions to catch any out-of-memory or string allocation errors and make sure things are cleaned up properly, but that's later.

However, if you are just going to parse that string into a vector or something, parsing the word list into the vector as you're reading it in from a file might be better. Otherwise, you'll have both the original word list in memory and the parsed list. All depends on what you're doing.

devcpp.exe is not the compiler. It's the IDE and it looks like it's a little buggy. That access violation might be because devcpp.exe has a memory leak or something.

If you use Mingw directly, make your cpp files in a text editor and build your cpp files on the command line, you'll be better off.

I tried building your backup main cpp files. I get a whole bunch of "comparison between signed and unsigned int" errors.

Get mingw by itself and install it so that g++.exe is in c:\mingw\bin. Then, you just add c:\mingw\bin to your PATH.

Then, you just fire up the command line, change to the directory where the cpp file is at and do:

g++ -Wall -Wextra file.cpp -o file -O3 -s

That will produce file.exe. (-s calls strip.exe on the file and -O3 adds lots of optimizations. You can look up the docs on them. )

The -Wall and -Wextra are very important to catch errors that you're missing.

Then, you won't be limited by devcpp's problems.
blaqDeaph's Avatar
Senior Member with 881 posts.
 
Join Date: Nov 2005
Location: Down Under!
Experience: Enough
22-Sep-2006, 02:35 AM #11
Quote:
Originally Posted by Shadow2531
What error does it give you?

Doing const string("very large string"); should compile and work as long as you have the mem.

How is the word list set up and how is it supposed to be used exactly?
Probably s/he run out of memory, since s/he said that the program can only be run a few times? Probably a windows related memory leak somewhere.
Shadow2531's Avatar
Senior Member with 2,640 posts.
 
Join Date: Apr 2001
22-Sep-2006, 11:08 AM #12
^^
Could be.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:09 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.