I am starting to learn how to use Sqlite and build databases however I would like to be able to work with these databases in C++. Whenever I start I am unable to accomplish anything because Visual Studio gives me the error in the title. when I try:
#include <sqlite3.h>
I have tried moving all of the code from sqlite's amalgamation into my project file and it still did not work. I tried using:
"sqlite3.h"
instead of
<sqlite3.h>
I also added the 'amalgamation' folder as a directory which makes the first error away but I am given a linker error on the build.
I feel as though I missed something in the setup that is not allowing me to do continue, but I have searched everything I can imagine and found no answers. Any help would be greatly appreciated. Thank you.
UPDATE: I am in a CLR project because I will need to attach a GUI to this Database and I am unable to compile the .c files from the amalgamation. Those files seem to be the solution to my problem though, so is there any way to get around that issue of a C file not being able to be compiled in a CLR project?
The following method demonstrate how to link with sqlite3.dll.
Download and copy the following folder to your Visual C++ solution folder.
https://github.com/mcychan/DNAssist/tree/master/sqlite3
The sqlite3 folder contains both x86 and x64 version of sqlite dll and lib.
You may upgrade to latest version of sqlite.dll.
Download and copy the following files to your Visual C++ project folder, add reference for them.
https://github.com/mcychan/DNAssist/blob/master/DNAssist/CppSQLite3.cpp
https://github.com/mcychan/DNAssist/blob/master/DNAssist/CppSQLite3.h
The following is the sample code to query the database.
#include "CppSQLite3.h"
#include <iostream>
#include <string>
using namespace std;
CppSQLite3DB db;
bool GetDatabase(const string& dbPath)
{
try {
db.open(dbPath.c_str());
return true;
}
catch (CppSQLite3Exception& e)
{
cout << _T("Cannot open database: ") << dbPath << _T("\n");
return false;
}
}
void IssueQuery(const string& querystring, const string& field1)
{
try {
CppSQLite3Query q = db.execQuery(querystring.c_str());
while (!q.eof()) {
CString temp2(q.fieldValue(field1.c_str()));
TRACE(temp2 + _T("\n"));
q.nextRow();
}
}
catch (CppSQLite3Exception& e)
{
cout << _T("Cannot execute query: ") << querystring << _T("\n");
}
}
void main()
{
if(GetDatabase("C:\\test.sqlite"))
IssueQuery("SELECT * FROM DUAL", "X");
}
Related
I'm currently working on a project where I need to read the Oculus Rift DK2 sensors. I have searched the web for usable samples, sadly the only samples I can find cause me a lot of trouble with SDK vesions and such. I found a tutorial on how to implement some basic C++ code to read the pitch, roll & yaw. I used the SDK for Windows V1.8.0.
#include "stdafx.h"
#include <iostream>
#include "../../OculusSDK/LibOVR/Include/OVR_CAPI.h"
#include <thread>
#include <iomanip>
#define COLW setw(15)
using namespace std;
int main()
{
// Initialize our session with the Oculus HMD.
if (ovr_Initialize(nullptr) == ovrSuccess)
{
ovrSession session = nullptr;
ovrGraphicsLuid luid;
ovrResult result = ovr_Create(&session, &luid);
if (result == ovrSuccess)
{ // Then we're connected to an HMD!
// Let's take a look at some orientation data.
ovrTrackingState ts;
while (true)
{
ts = ovr_GetTrackingState(session, 0, true);
ovrPoseStatef tempHeadPose = ts.HeadPose;
ovrPosef tempPose = tempHeadPose.ThePose;
ovrQuatf tempOrient = tempPose.Orientation;
cout << "Orientation (x,y,z): " << COLW << tempOrient.x << ","
<< COLW << tempOrient.y << "," << COLW << tempOrient.z
<< endl;
// Wait a bit to let us actually read stuff.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
ovr_Destroy(session);
}
ovr_Shutdown();
// If we've fallen through to this point, the HMD is no longer
// connected.
}
return 0;
}
there are (as far as I know) no problems with this part.
when I included the OVR_CAPI.h the OVR_CAPI.cpp magically appears in the folder where OVR_CAPI.h is located. this cpp file contains the following:
#include "stdafx.h"
#include "OVR_CAPI.h"
OVR_PUBLIC_FUNCTION(ovrResult) ovr_Initialize(const ovrInitParams * params)
{
return OVR_PUBLIC_FUNCTION(ovrResult)();
}
when I try to build it errors:"expected an expression" and " C2062(type 'int' unexpected)" occur,both on Line 6.
is anyone familiar with this problem or can someone give me advice on how to get started with Oculus software?
You have included the source of the LibOVR. You have to compile LibOVR to a .lib file in visual studio and add that to your project instead.
Step 1
In the LibOVR folder, there should be a "Projects folder". Open the version for your visual studio version.
Step 2
Compile the LibOVR project (in release mode), this shouldn't give any errors. If it does, the library might be corrupted. Try downloading the source again from the oculus website or try a different version.
Step 3
When successful copy the LibOVR.lib file from the build folder and the "Include" folder to your own project (I suggest creating a new "libs" folder in your project directory).
Step 4
Close the LibOVR project and open your own. Open the property window for your project and in VC++ Directories add the "Include" folder to the "Include Directories". Also add the the folder where the .lib file is located to the "Library Directories".
Finally in the "Linker->Input" settings add LibOVR.lib to the "Additional Dependencies" if you didn't already.
Step 5
Add this to your main.cpp file
#include <OVR_CAPI.h>
Try compiling your project. Everything should work now.
Does anyone know why the file isn't opening? I also tried just putting "infile.txt" and placing it in the folder of the program and also the debug folder but the ways I used to check for open error both triggered meaning that it could not open. I know I can hard code the location but I don't want to.
I heard you should do stringobj.c_str() but I don't know if that's accurate?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
string fileloc = "infile.txt";
infile.open(fileloc);
if (!infile)
{
cout << "open fail 1" << endl;
}
bool fail = infile.fail();
if (fail)
{
cout << "open fail 2";
}
return 0;
}
Note that the directory structure (at least for VS2013) is
<base>
- Solution Directory
- Debug
- Release
- Project Directory
- Debug
- Release
The program by default runs in the project directory (even though it is built to the solution/debug directory).
If you accepted the default naming convention when starting your project, you should be putting your file in the "Projects\ConsoleApplication1\ConsoleApplication1" directory, not "Projects\ConsoleApplication1"
Check your working directory in Project Settings -> Debugging. Make your file available there.
First, the documentation for the signature of
std::ifstream::open( const char * filename, ios_base::openmode mode=ios_base::in)
does indicate it requires a const char *, exactly what std::string::c_str() provides. However, there is an overload for open which accepts a const str &, which means it works the same way for both on most implementations.
Otherwise, what you're grappling with is known as the current working directory (or cwd). Apparently you're not sure where THAT directory is. It may be different while you run the debugger on Visual Studio than it is when you run your program from the command line, and it may be different in various IDE's.
I'm not sure why you want to ensure your program only opens a file by name in the current directory, and not give the full path, but...
You may want to inquire what the current working directory is, so you can solve the mystery wherever you try this. In my Visual Studio 2015, the directory ends up being the directory ABOVE debug, but that depends entirely on how your project is configured, and we can't see that out here.
So, try:
std::string cwd = getcwd( NULL, 0 );
This requires a header <direct.h> on Windows in Visual Studio, but it will give you the directory you're trying to figure out.
with
string fileloc = "infile.txt";
if you put infile.txt in the same folder of the cpp file, it should be fine.
btw I delete your first line
#include "stdafx.h"
I use cygwin console, may have minor diff
For my issue - i was stuck at loading image by opencv - i was wrong to place directory with jpg in the root of the C++ project
WRONG:
CORRECT:
I keep getting this error with these lines of code:
include <iostream>
int main()
{
cout << "Hello World" >>;
system("pause");
return 0;
}
"The system cannot find the file specified"
The system cannot find the file specified usually means the build failed (which it will for your code as you're missing a # infront of include, you have a stray >> at the end of your cout line and you need std:: infront of cout) but you have the 'run anyway' option checked which means it runs an executable that doesn't exist. Hit F7 to just do a build and make sure it says '0 errors' before you try running it.
Code which builds and runs:
#include <iostream>
int main()
{
std::cout << "Hello World";
system("pause");
return 0;
}
The code should be :
#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
return 0;
}
Or maybe :
#include <iostream>
int main() {
std::cout << "Hello World";
return 0;
}
Just a quick note: I have deleted the system command, because I heard it's not a good practice to use it. (but of course, you can add it for this kind of program)
I had a same problem and this fixed it:
You should add:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64 for 64 bit system
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib for 32 bit system
in Property Manager>Linker>General>Additional Library Directories
Another take on this that hasn't been mentioned here is that, when in debug, the project may build, but it won't run, giving the error message displayed in the question.
If this is the case, another option to look at is the output file versus the target file. These should match.
A quick way to check the output file is to go to the project's property pages, then go to Configuration Properties -> Linker -> General (In VS 2013 - exact path may vary depending on IDE version).
There is an "Output File" setting. If it is not $(OutDir)$(TargetName)$(TargetExt), then you may run into issues.
This is also discussed in more detail here.
This is because you have not compiled it. Click 'Project > compile'. Then, either click 'start debugging', or 'start without debugging'.
I resolved this issue after deleting folder where I was trying to add the file in Visual Studio. Deleted folder from window explorer also. After doing all this, successfully able to add folder and file.
I was getting the error because of two things.
I opened an empty project
I didn't add #include "stdafx.h"
It ran successfully on the win 32 console.
I've reinstalled Visual Studio 2010 Professional several times to try to get it to work.
I had to uninstall Visual Studio 2012 Professional because it wasn't compiling something we did in class.
I completely uninstalled everything including SQL Server..
I went to VC/include and the iostream header file is not there.
#include <iostream>
int main () {
cout << "hello";
system ("PAUSE");
return 0;
}
This is all I'm trying to do because nothing else is working.
It's really driving me crazy because I need to get it working so that I can do my project!!!
Every time I do; new project => empty project => add an item to source =>.cpp
I'm running windows 8.
It just says Error cannot open source file
Also, error cout identifier is undefined....
I'm wondering if I should do a system restore?
Or if I should just completely reinstall windows 8 from my recovery media?
One problem is that you did not include the namespace std.
This is what your code should look like:
#include <iostream>
using namespace std;
int main (void) {
cout << "hello" << endl;
system("pause");
return 0;
}
or you could have done something like this: std::cout << "Hello" << std::endl;
This may be a problem because you did not set your environment to C++. This is how you do it:
Go to Tools > Import and Export settings. If you cannot find it, just search for it in Quick Search
Then go to reset all settings.
Then simply select "Visual C++"
Restart.
That should do the trick. If it does not, you might consider re-installing Visual C++ itself. For VS 2012. If that does not work, then re-install the program.
if it is problem with visual studio 2012, install this update.
I'm trying to do something basic
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!";
return 0;
}
After using F7 I get
1>mt.exe : general error c10100b1: Failed to load file "..\Debug\helloworld.exe". The system cannot find the path specified.
So it cant find the file that it'll eventually create?
What gives?
mt.exe is the manifest tool. The manifest tool shouldnt run if there is a build error. I dont think you will see mt.exe run if there is a build error. Go to your solution file, under the manifest tab, check if the path's in the settings are not hard coded to some wrong path.
#include <.iostream.>
Did your build really succeed? The above line looks suspicious - I'd have expected to see (note the missing periods):
#include <iostream>