问题描述
我是C ++的新手,我试图使用SQLite3.h访问一个预填充的数据库。我将数据库文件(.db)添加到资源中,将其放置在与项目相同的文件夹中,并将sqqlite3.h添加到头文件夹。在主.cpp文件中,我只包括以下行。
I'm very new to C++ and I'm trying to use SQLite3.h to access a database that is pre-filled. I added the database file (.db) to resources, placed it in same folder as project and added "sqqlite3.h" to header file folder.In the main .cpp file, I included just the following line.
#include "MyDatabase.db"
我得到几个错误,如下所示。
I'm getting several errors such as below.
1>------ Build started: Project: SQLiteLibrary, Configuration: Debug Win32 ------
LibNew.cpp
error C2146: syntax error : missing ';' before identifier 'format'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2143: syntax error : missing ';' before 'constant'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2018: unknown character '0x4'
error C2018: unknown character '0x1'
error C2018: unknown character '0x1'
error C2018: unknown character '0x40'
error C2018: unknown character '0x6'
error C2018: unknown character '0xe'
error C2018: unknown character '0x4'
error C2018: unknown character '0x2'
error C2018: unknown character '0x6'
error C3872: '0x4': this character is not allowed in an identifier
error C2018: unknown character '0x5'
error C2018: unknown character '0x4'
error C2018: unknown character '0x3'
error C2018: unknown character '0x1d'
error C2018: unknown character '0x3'
error C2018: unknown character '0x3'
error C2018: unknown character '0x3'
error C2018: unknown character '0x3'
error C2018: unknown character '0x7'
error C2018: unknown character '0x7'
error C2018: unknown character '0x1'
fatal error C1004: unexpected end-of-file found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
在这些错误之前,有数据库文件的位置。它似乎它试图读取.db文件和显示错误。
Before these errors there is the location for database file. It seems its trying to read the .db file and showing errors.
有一种方法可以将数据库作为资源,而不是C ++试图读取它。 (所有的.db文件中的信息都在表中。所以我很好奇C ++能够读取任何东西)。
Is there a way to include the database as a resource without C++ trying to read it. (All the information in .db file is in tables. So I'm curious about how C++ is able to read anything at all).
推荐答案
MyDatabase.db
不是库。您必须使用 include
将 .h
头文件导入到您的 .cpp
程序。
MyDatabase.db
is not a library. You must use include
to import .h
header files to your .cpp
program only.
,,和,您可以在C / C ++中找到一些使用 sqlite 数据库的方法。
Here , here , here and here you can find some methods to work with sqlite databases in C/C++.
这篇关于将数据库文件包含在C ++项目中时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!