问题
In the internet there are databases(mysql, oracle etc.) where I can send the informations submitted by the HTML input fields with PHP or any other server side language.
How is this working in C/C++? How can I let a user input something and them save the inputted value?
回答1:
You can either:
- Make use of the standard file handling functions/classes.
- Embed a tiny database.
- Talk to a database server using a standard interface.
BTW, these are common for all languages.
回答2:
Really depends what you want to save.
There are libraries (like this one) that will let you connect to SQL databases from C++.
Another approach would be to save/load it to a file. For simple things just filestreams may be good enough, other times you may want something a bit more hard-wearing like boost::serialization to take some of the hard work out of it.
回答3:
Are your talking about desktop(standalone) application or some web-app? And it depends on what type of information are you going to store. Perhaps, windows registry would be enough.
Also you can use MySQL for storing data. There are a lot of tutorials on how to work with MySQL via C++. Here's a convinient api.
And your should read this.
回答4:
Why are you thinking C/C++ is different than other languages (like PHP) concerning the storage of data? You can save your data:
- in a database (need an Open Database Connection)
- in a tiny database such as SQLite
- in a file
You can choose the way you want.
回答5:
To let the user input something beyond the command-line you need a GUI toolkit. To communicate with databases you need a framework like MySQL Connector/C++.
回答6:
look also at the following: libodbc++ - a C++ wrapper for ODBC, much more convenient than a plain C ODBC.
if you work on Linux, you may find useful info here: UnixODBC - The popular ODBC infrastructure for Linux.
来源:https://stackoverflow.com/questions/4322794/how-to-save-data-in-c-c