I try to open a file with ifstream but as soon as I try to declare a ifstream or ofstream variable I get LNK1104. The header works and the rest of the code also works.
#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;
}
I tried to to change the header to fstream.h or .c because I thought it would be a problem with the header. But I have 0 clue what else I could try.
Delete the file
C:\Meins\Uebungen\C++\TryoutDatabase\x64\Debug\TryoutDatabase.exe, then run the build again.If Windows doesn't let you delete the file, that may be because the program TryoutDatabase.exe is still running. Kill the program first by closing its window or from Task Manager.
Microsoft documentation of LNK1104 here.