我尝试用ifstream打开一个文件,但是当我尝试声明一个ifstream或ofstream变量时,我得到了LNK1104。头部工作,其余的代码也工作。
#include "sqlite/sqlite3.h"
#include <string>
#include <stdio.h>
#include <iostream>
#include <fstream>
static int createDB(const char* s);
static int createTable(const char* s);
static int insertData(const char* s);
static int showAllTableEntries(const char* s, std::string table);
static int callback(void* NotUsed, int argc, char** argv, char** azColName);
static int updateData(const char* s, std::string table, int id, std::string toChange, std::string newValue);
static int updateData(const char* s, std::string table, int id, std::string toChange, int newValue);
int main()
{
const char* dir = "C:\\Meins\\Uebungen\\C++\\TryoutDatabase\\TryoutDatabase\\Tryout2.db";
sqlite3* DB;
createDB(dir);
createTable(dir);
return 0;
}
static int createDB(const char* s)
{
sqlite3* DB;
int exit = 0;
exit = sqlite3_open(s, &DB);
sqlite3_close(DB);
return 0;
}
static int createTable(const char* s)
{
sqlite3* DB;
std::string sql_statements;
/*std::ifstream sql_file; // as soon as i add this line to the code i get the LNK1104
sql_file.open("C:\\Meins\\Uebungen\\C++\\DatabaseMarketAnalysis\\DataBase\\DB_Setup.sql");
if (sql_file.is_open()) {
sql_statements = sql_file.get();
}*/
// sql statement
std::string sql = sql_statements;
try
{
// open the database
int exit = sqlite3_open(s, &DB);
char* messageError;
// execute the statement
exit = sqlite3_exec(DB, sql.c_str(), NULL, 0, &messageError);
if (exit != SQLITE_OK)
{
std::cerr << "Error Create Table" << std::endl;
sqlite3_close(DB);
}
else
{
std::cout << "Table created successfully" << std::endl;
}
sqlite3_close(DB);
}
catch (const std::exception & e)
{
std::cerr << e.what();
}
return 0;
}
字符串
我试着把头文件改为fstream. h或.c,因为我觉得这会是头文件的问题。但是我没有其他的方法可以尝试。
1条答案
按热度按时间kq4fsx7k1#
删除文件
C:\Meins\Uebungen\C++\TryoutDatabase\x64\Debug\TryoutDatabase.exe
,然后再次运行构建。如果Windows不允许您删除该文件,可能是因为程序TryoutDatabase.exe仍在运行。请先关闭程序窗口或从任务管理器中终止该程序。
微软的LNK1104 here文档。