3than7 said:
ohh no, i AAMM intrested in developing a program, and by the end of the
year i might even be able to install it at school if its comprehensive
enough.
I have Dev-C++ from Bloodshed, wich im almost positive youve heard of,
however when i compiled what youve writen, it returned an error at the
second to last line saying was expecting } sooner. Now how do i make
the program work with a database or whatever you were referencing.
thanks~3than7
Yes, Bloodshed will do. As far as the } is concerned, unless the last
one was parsed away by whatever you are using to read the newsgroups,
that program is correct and definitely compiles.
Perhaps you are missing a newline at the end of source which is
preventing bloodshed from parsing the last }.
You don't need a database, std::map is a database which uses a special
kind of tree structure to facilitate extremely quick searches. Whenever
you add "records", which are in form of std:

air< string, string > in
this case, they are automatically ordered using a default algorithm
(std::less<> which orders keys in assending order). Regardless of the
order you add records, that container inserts them ordered
automatically.
http://www.sgi.com/tech/stl/Map.html
To store the database, you'll need to learn how to use std:

fstream to
write to files and std::ifstream to read from files. Which is actually
quite easy to do but lets do one thing at a time - doing std::maps is
already a big leap over a lot of important details. Eventually, you'll
end up with a database that will look like this in the file - the left
string is the key, $ is used as seperator and terminator: In fact, many
commercially available databases today use this very format.
apple$translation of apple$
banana$translation of banana$
carrot$translation of carrot$
date$translation of date$
Once you get the program to compile, add the following immediately
after the record insertions and before the try { } block to display all
the records. Note: you can change the order of the insertions (ie:
apple after carrot) but the result is the same.
int main()
{
... // std::map insertions
// add the following
std::cout << "number of records: " << translaotor.size();
std::cout << std::endl;
typedef std::map< std::string, std::string >::iterator MIter;
for(MIter miter = translator.begin(); miter != translator.end();
++miter)
{
std::cout << (*miter).first << "\t";
std::cout << (*miter).second << std::endl;
}
std::cout << std::endl;
// end of new section
try {
...
} catch ( ... )
{
...
}
}
You should get something like:
/* output:
number of records: 4
apple trans of apple
banana trans of banana
carrot trans of carrot
date trans of date
Enter a string to find the translation for: apple
result: translation of apple
Enter y to try again (enter any other key to stop): f
*/
You can't add a second apple entry, std::map only supports unique keys,
thats where the std::multimap comes in.