I've looked online for how to play a audio file on C++ and looked at videos but most of them say to change the 'linker' to winmm library. The problem I have is finding where to change the properties in VSCode 2019. Also, when I try to use #Include it would show an error. Example:
#Include "stdafx.h"
#Include <Windows.h>
#Include <playsoundapi.h>
int main()
{
PlaySound(TEXT("C:\Users\User\Desktop\Sound\Blop.wav"), NULL, SND_FILENAME);
return 0;
}
My goal is to just play an audio file using C++ from VSCode.
Error -: cannot open source file "stdafx.h"´ ´cannot open source file "Windows.h"´ ´#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\User\Desktop\Sound\Audio.cpp).´ ´cannot open source file "playsoundapi.h"
It is not #Include. It should be correct as #include
I already was a problem seem like you. So, by my experience, I think "#Include "stdafx.h" is the problem, you can't use "stdafx.h" in VS 2019 (Microsoft Visual Studio Comunity 2019), "stdafx.h" work very well in VS 2017 (Microsoft Visual Studio Comunity 2017), but "stdafx.h" was replaced by #include "pch.h"in VS 2019, in other words, you should use #include "pch.h" and not "stdafx.h". And more, you have to include the winmm.lib in linker/imput/aditional dependencies, so if you follow this link you can see how to include winmm.lib (https://www.youtube.com/watch?v=9WeDQHi6sJs). So, to VS 2019 you can use this code below, I use this code in VS 2019 and it works very well for me. The song that you would like to play should have to stay in the right directory, the name of the file that stays my .cpp code is teste_0027 (C:\Users\Rodrigo\source\repos\teste_0027\Debug), the file has to stay in .wav format, and more, when you will create the c++ project in VS 2019 you should create the project as model "Aplicativo de Console CLR" in my language (Portuguese-Brazil), in your language it should sound like "Console App CLR"...
#include "pch.h"
#include <iostream>
#include <windows.h>
#include <MMSystem.h>
using namespace System;
using namespace std;
int main()
{
bool played = PlaySound(TEXT("ALAN-WALKER-Faded-Different-World-feat-Julia.wav"), NULL, SND_SYNC);
cout << " Sucess or not " << played << endl;
system("pause");
return 0;
}
Dear StackOverFlow experts,
I have searched and searched for a solution to this problem but have not found an answer. I have found people with similar questions but not an answer. I humbly ask for your forgiveness if I have overlooked a solution. With this I ask you to please consider my submission.
I have a simple test code for OpenCV 2.4.11 in Visual Studio 2010 x64
#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <opencv2\opencv.hpp>
#include <opencv2\core\types_c.h>
using namespace cv;
int main(){
IplImage* img=cvLoadImage("C:\\Users\\Russ\\Pictures\\3-7-15\\_DSC8489.jpg"); //change the name
cvNamedWindow("Example1",CV_WINDOW_NORMAL );
cvShowImage("Example1",img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow( "Example1");
return 0;
}
When I Build this I get an error
C:\opencv\build\include\opencv2/core/types_c.h(55): fatal error C1083: Cannot open include file: 'assert.h': No such file or directory
All of the opencv includes are included in my properties path as are my libraries for OpenCV. When I open the types_c.h file I see the following
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
//M*/
#ifndef __OPENCV_CORE_TYPES_H__
#define __OPENCV_CORE_TYPES_H_
#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER
# if _MSC_VER > 1300
# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
# endif
#endif
#ifndef SKIP_INCLUDES
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#if !defined _MSC_VER && !defined __BORLANDC__
# include <stdint.h>
#endif
#...
Since assert.h is used for debugging, I decided to comment out the assert.h line. When I Build the code again I got this error.
C:\opencv\build\include\opencv2/core/types_c.h(56): fatal error C1083: Cannot open include file: 'stdlib.h': No such file or directory
Clearly something is not set properly for Visual Studio 2010 as it can not find these libraries. Can someone tell how to fix this problem in Visual Studio 2010 x64. Thanks for your help.
For your case, you only need to include opencv2/opencv.hpp to make it work.
Also, since you're using C++, it's strongly recommended to use OpenCV's C++ API over deprecated C API. The code will be like:
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat img = cv::imread("C:\\Users\\Russ\\Pictures\\3-7-15\\_DSC8489.jpg");
cv::namedWindow("Example1", CV_WINDOW_NORMAL);
cv::imshow("Example1", img);
cv::waitKey(0);
cv::destroyWindow("Example1");
return 0;
}
Updated:
If you still encounter with problems, you should follow this post to setup OpenCV correctly with VS.
Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.
I am new to C++. I just started! I tried a code on Visual C++ 2010 Express version, but I got the following code error message.
------ Build started: Project: abc, Configuration: Debug Win32 ------
ugo.cpp
c:\users\castle\documents\visual studio 2010\projects\abc\abc\ugo.cpp(3): fatal error C1083: Cannot open include file: 'iostream': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This is the code:
// first.cpp -- displays a message
#include <iostream> // A PREPROCESSOR directive
int main(void) // Function header
{ // Start of a function body
using namespace std;
cout << "Come up and C++ me sometime.\n"; // Message
// Start a new line
cout << "Here is the total: 1000.00\n";
cout << "Here we go!\n";
return 0;
}
Replace
#include <iostream.h>
with
using namespace std;
#include <iostream>
Some things that you should check:
Check the include folder in your version of Visual Studio (in "C:\Program Files\Microsoft Visual Studio xx.x\VC\include", check for the file which you are including, iostream, make sure it's there).
Check your projects Include Directories in <Project Name> → Properties → Configuration Properties → VC++ Directories → Include Directories (it should look like this: $(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)include;$(FrameworkSDKDir)\include;)
Make sure that you selected the correct project for this code
(menu File → New → Project → Visual C++ → Win32 Console Application)
Make sure that you don't have <iostream.h> anywhere in your code files, Visual Studio doesn't support that (in the same project, check your other code files, .cpp and .h files for <iostream.h> and remove it).
Make sure that you don't have more than one main() function in your project code files (*in the same project, check your other code files, .cpp and .h files for the* main()` function and remove it or replace it with another name).
Some things you could try building with:
Exclude using namespace std; from your main() function and put it after the include directive.
Use std::cout without using namespace std;.
I had this exact same problem in Visual Studio 2015. It looks like as of Visual Studio 2010 and later you need to include #include "stdafx.h" in all your projects.
#include "stdafx.h"
#include <iostream>
using namespace std;
The above worked for me. The below did not:
#include <iostream>
using namespace std;
This also failed:
#include <iostream>
using namespace std;
#include "stdafx.h"
You are more than likely missing $(IncludePath) within Properties → VC++ Directories → Include Directories.
Adding this should make iostream and others visible again. You probably deleted it by mistake while setting up your program.
If your include directories are referenced correctly in the VC++ project property sheet → Configuration Properties → VC++ directories → Include directories, the path is referenced in the macro $(VC_IncludePath).
In my Visual Studio 2015 this evaluates to:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include"
using namespace std;
#include <iostream>
That did it for me.
It is possible that your compiler and the resources installed around it were somehow incomplete. I recommend re-installing your compiler: it should work after that.
I got this error when I created an 'Empty' console application in Visual Studio 2015. I recreated the application, leaving the 'Empty' box unchecked. It added all of the necessary libraries.
Make sure you have Desktop Development with C++ installed.
I was experiencing the same problem, because I only had Universal Windows Platform Development installed.
Microsoft Visual Studio is funny. When you're using the installer, you must checkbox a lot of options to bypass the .NET framework (somewhat) to make more C++ instead of C# applications, such as the CLR options under desktop development... in the Visual Studio installer.... the difference is the C++ Win32 console project or a C++ CLR console project.
So what’s the difference? Well, I'm not going to list all of the files CLR includes, but since most good C++ kernels are in Linux... So CLR allows you to bypass a lot of the Windows .NET framework because Visual Studio was really meant for you to make applications in C#.
Here’s a C++ Win32 console project!
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
cout << "Hello, World!" << endl;
return 0;
}
Now here’s a C++ CLR console project!
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine("Hello, World!");
return 0;
}
Both programs do the same thing .... the CLR just looks more frameworked class overloading methodology, so Microsoft can great its own vast library you should familiarize yourself with if so inclined.
Keywords (C++)
Other things you'll learn from debugging to add for error avoidance:
#ifdef _MRC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
If you created an environment variable with the name IncludePath, try renaming it to something else.
This name will override $(IncludePath) inside project properties.
Quick fix for small programs:
Add: #include <cstdlib>
In my case, my Visual Studio 2015 installed without selecting C++ package, and Visual Studio 2017 is installed with the C++ package. If I use Visual Studio 2015, opening a C++ project will show this error, and using Visual Studio 2017 will be no error.
I had this problem too. I used this code (before main();) in Visual Studio 2022, and it turned OK:
#include "pch.h"
#include <iostream>
using namespace std;
using namespace winrt;
using namespace Windows::Foundation;
In my case, the error occurred when I created a file in VS Code, without giving the .cpp extension. It resolved when I renamed it with the .cpp.
// first.cpp -- displays a message
#include <iostream> // a PREPROCESSOR directive
using namesapce std;
int main() // function header
{ // start of a function body
///using namespace std;
cout << "Come up and C++ me sometime.\n"; // message
// start a new line
cout << "Here is the total: 1000.00\n";
cout << "Here we go!\n";
return 0;
}
I am trying to get protobuf into xcode 4 and work with ios 5. I've done other tutorials none have worked. I have used a script to compile the libraries into arm 7 architecture and then added them to my project. This is the only thing that has worked so far.
My issue now is that I am trying to use the c++ generated files; however, I am getting an error saying #include -> lexical or preprocessor issue.
Any tips? It only showed this when I tried to run my project on the ipad. Before, it was fine with it.
Thanks. :)
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: addressbook.proto
#ifndef PROTOBUF_addressbook_2eproto__INCLUDED
#define PROTOBUF_addressbook_2eproto__INCLUDED
#include <string>
#include <google/protobuf/stubs/common.h>
//#include "google/protobuf/stubs/common.h"
#if GOOGLE_PROTOBUF_VERSION < 2004000
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers. Please update
#error your headers.
#endif
#if 2004001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers. Please
#error regenerate this file with a newer version of protoc.
#endif
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/repeated_field.h>
#include <google/protobuf/extension_set.h>
#include <google/protobuf/generated_message_reflection.h>
Update: This only breaks when I include it in an obj c file. I can make a Demo.h and include addressbook. Why can't I include addressbook.pb.h into an obj c file? Am I missing a setting somewhere? Which one?