简体   繁体   中英

How To Connect SQLite with C++?

Can someone please tell me how do i make SQLite to connect with my C++ program. I am a complete beginner in programming and is trying to make a very basic project on a banking system. I thought of storing the transactions made by the account holders in a sql database and came across sqlite. Then i tried to look for how to connect the two but could not find anything. Dissapointed i tried doing sommething like this:

ofstream fout;
fout.open("crtab.sql", ios_base::ate);
fout << ".open test.db" << endl <<"CREATE TABLE " << name << "(id integer);" << endl << ".exit";
fout.close();
system("sqlite3.exe crtab.sql");
 cout << "Database Updated";

` This did not work either. My teacher suggests me to store the data in a text file but i think it's a stupid idea. My Operating System is Windows 10 and ide is dev-c++ with TDM-GCC 4.9.2 I also have Visual Studio 2017 Community installed. Which one should i use?? Please help quick.

SQLite Databases are stored in files, so you just need to open them. But you can't just use fopen or streams, you have to use the appropiate function that SQLite provides, which seems to be this one .

Finally got it working. First I downloaded the sqlite-amalgamation zip. Then i extracted the files sqlite3.h and sqlite3.c and fnally i used gcc like this gcc main.cpp sqlite3.c This got the the test program to work.

Thanks to all the helpers...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM