From b6eb04e37c4b40ab6e7c1948196dd4e04adce721 Mon Sep 17 00:00:00 2001 From: Kartik Kumar Date: Thu, 26 Mar 2015 10:54:18 +0100 Subject: [PATCH] Changes paths to example db and logo to absolute paths using helper function to extract path to examples sub-directory. --- examples/example1/main.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/example1/main.cpp b/examples/example1/main.cpp index c73c66a..c475319 100644 --- a/examples/example1/main.cpp +++ b/examples/example1/main.cpp @@ -13,8 +13,7 @@ #include #include #include -#include - +#include #include @@ -31,10 +30,17 @@ void assertion_failed(const char* apFile, const long apLine, const char* apFunc, } #endif +/// Get example path +static inline std::string getExamplePath() +{ + std::string filePath(__FILE__); + return filePath.substr( 0, filePath.length() - std::string("main.cpp").length()); +} + /// Example Database -static const char* filename_example_db3 = "examples/example1/example.db3"; +static const std::string filename_example_db3 = getExamplePath() + "/example.db3"; /// Image -static const char* filename_logo_png = "examples/example1/logo.png"; +static const std::string filename_logo_png = getExamplePath() + "/logo.png"; /// Object Oriented Basic example @@ -307,7 +313,7 @@ int main () db.exec("DROP TABLE IF EXISTS test"); db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value BLOB)"); - FILE* fp = fopen(filename_logo_png, "rb"); + FILE* fp = fopen(filename_logo_png.c_str(), "rb"); if (NULL != fp) { char buffer[16*1024];