LNK1104 声明 ifstream 或 ofstream 变量时

问题描述 投票:0回答:1

我尝试使用 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,因为我认为这会是标头的问题。但我不知道我还能尝试什么。

c++ linker-errors fstream
1个回答
1
投票

删除文件

C:\Meins\Uebungen\C++\TryoutDatabase\x64\Debug\TryoutDatabase.exe
,然后再次运行构建。

如果 Windows 不允许您删除该文件,可能是因为程序 TryoutDatabase.exe 仍在运行。首先通过关闭其窗口或从任务管理器来终止程序。

© www.soinside.com 2019 - 2024. All rights reserved.