I'm a new to c++ and the task I'm currently trying to solve is to parse some data in *.txt file in one directory to the *+1.txt file in the other directory.
I've used the sample of code:
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
int main(int argc, char*argv[]){
std::ifstream input("C:\\Tmp\\example.txt");
std::string outfilepass = "";
outfilepass +=argv[2];
outfilepass +="\\";
outfilepass += argv[1];
std::ofstream outfile(outfilepass);
return 0;
}
If I compile it and then use
sample.exe example1.txt "C:\Tmp\NewFolder\" everything is works fine in windows 10, but nothing happens in windows 7.
!Update
I've found some useful links that helped me to find the solution. Problem was in target platform for the application. (I've used VS 2019). Here are some useful links:
Visual Studio 2015 Change target platform to windows 7
https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?redirectedfrom=MSDN&view=vs-2019
I've found some useful links that helped me to find the solution. Problem was in target platform for the application. (I've used VS 2019). Here are some useful links:
Visual Studio 2015 Change target platform to windows 7
https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?redirectedfrom=MSDN&view=vs-2019
The solution was build in release with
#define WINVER 0x0601 и _WIN32_WINNT 0x0601
Related
I am trying to use clocks to measure the time of the running program in Visual Studio 2015 (x64) with C++ on Windows in Debug x64 mode.
I get errors in these lines:
#include <time.h>
#include <sys/timeb.h>
The errors messages say:
cannot open source file "time.h"
cannot open source file "sys/timeb.h"
What path do I have to add to include directories in order to fix this error?
You could try #include <ctime>
Refer to this: http://www.cplusplus.com/reference/ctime/
time.h is used is C not C++.
read this it explain that your method is POSIX, so your path to the sys/time.h must be set well
but there are 2 others way for : how to get time in milliseconds with cpp
https://www.delftstack.com/howto/cpp/how-to-get-time-in-milliseconds-cpp/
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;
}
I'm trying to play a RTSP stream in Unity 5.
For that I found a RTSP-plugin for Unity on Github that I want to try, but unfortunatelly it comes with no Readme or installation guide whatsoever.
So far I found out that I'm dealing with a C++ Visual Studio project that needs to be compiled into a DLL in order to add it to Unity. But when I try to build the project I get the following Error for the header file "ffmpegenv.h":
Error C1083 Cannot open include file: 'libavutil\opt.h': No such file or directory - (Screenshot)
Here's the code from the header file
#pragma once
//=============================
// Includes
//-----------------------------
// FFMPEG is writen in C so we need to use extern "C"
//-----------------------------
extern "C" {
//#define INT64_C(x) (x ## LL)
//#define UINT64_C(x) (x ## ULL)
#include <libavutil\opt.h>
#include <libavutil/mathematics.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
#include <libavutil/imgutils.h>
#include <libavcodec/avcodec.h>
}
I'm aware that the header includes source code from the FFmpeg libraries which doesn't come with the plugin I'm trying to compile. So I downloaded the FFmpeg source code from their GitHub page and copied all the code files (with its original folder structure) inside the plugin's project folder.
However when I then try to compile the plugin, it still doesn't find the #includes an shows the same error as mentioned above.
How I can I get the plugin to compile? What am I missing?
Thanks in advance
P.S.: I'm using Visual Studio Community 2017 with C++ support and Win 10 SDK as well as Win 8.1 SDK.
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.
I'm compiling my application on a new box (vista 64) and now it doesn't compile anymore. The compiler gives me the error in the title. The problem seems(?) to be that HWINEVENTHOOK is defined twice in
windef.h
#if(WINVER >= 0x0400)
DECLARE_HANDLE(HWINEVENTHOOK);
#endif /* WINVER >= 0x0400 */
and then in winable.h it's
#if WINVER < 0x0500 // these structures and functions
// are in NT 5.00 and above winuser.h
typedef DWORD HWINEVENTHOOK;
However, I just looked up WINVER for vista and it is 0x0600 and windows XP is 0x0501 so why is DWORD being defined? I'm at a loss. Anyone help?
According to this MSDN forum thread:
winable.h was moved from the Windows
SDK in July 2005 because functionality
was duplicated in winuser.h. It was
determined at that time that efforts
would be better spent on updating
winuser.h to Windows Vista-level
functionality rather than updating the
functionality of both files.
What version of the Windows SDK are you using, and what Windows version is your code targetting? The target Windows version may be specified in a makefile, project file, or header file. Compiling your code on Vista doesn't necessarily mean that the target version is Vista.
Also, have you tried switching from winable.h to winuser.h?
You might need to explicitly set WINVER to the version corresponding to the minimum version of Windows you are targeting. I suspect its default value is not much above Win2K...
You could check its default value with a quick (untested) hack like this:
#include <windows.h>
#include <stdio.h>
int main(int argc, char **argv) {
printf("WINVER=0x%04x\n", WINVER);
return 0;
}
Compiled as a console app and run at the command prompt it might provide a clue. Otherwise, you'll spend ages chasing through include files trying to identify where it set the default.
Edit: In general, it is safest to always specify WINVER for a project. Either do it in the project settings in Visual Studio (and for all builds, not just the current build!) or do it in a common header file included by every module in the project. Doing so explicitly will reduce the chance that different build environment might have a different assumption.