I tried to load a .wav file(afschieten.wav), but I cant load it. I followed the tutorial of lazyfoo: http://lazyfoo.net/SDL_tutorials/lesson11/
The code:
I got this on top of file:
#include <stdlib.h>
#include "GL/glut.h"
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
the function I call from main:
void load_files(){
//Load sound effect
fire = Mix_LoadWAV( "afschieten.wav" );
if(fire != NULL)
std::cout << "Sound effect afschieten.wav loaded succesfully" << std::endl;
else
std::cout << "Sound effect afschieten.wav failed loading" << std::endl;
}//load_files
What am I doing wrong? I get no errors when compiling. It says sound effect afschieten.wav failed loading.
Check the path of the wav file: for proper loading, you should put it in the same directory of the executable, or use an absolute path.
Related
I'm trying to output the symbol of Electric Light Bulb with code U+1F4A1 to Windows Terminal (experiment with Unicode). I can't realize how to do that. I tried to use wchar_t, wcout, to change console output code page, and with no result. Who made it. please tell how to do that.
#include <uchar.h>
#include <iostream>
#include <cstdlib>
#include <clocale>
#include "Windows.h"
#include <io.h>
#include <fcntl.h>
int main() {
SetConsoleCP(12000);
SetConsoleOutputCP(12000);
/*Alternative*/
system("chcp 65001");
std::cout << u8"\u1F4A1" << std::endl;
return 0;
}
I'm making a program where it checks if the user has the required JRE installed so they are able to run jar files. And, if they don't have it, then it downloads and runs the file for them. However, I keep getting the same error no matter what type of method I find online and apply. It keeps telling me that its unable to find or open the exe. And when I check the download location, it doesn't download anything at all.
Code:
HRESULT hr = URLDownloadToFile(NULL, _T("https://download.oracle.com/otn/java/jdk/8u291-b10/d7fc238d0cbf4b0dac67be84580cfb4b/jre-8u291-windows-x64.exe"), _T( "c:\\jre-8u291-windows-x64.exe"), 0, NULL);
cout << "Download Complete" << endl;
cout << "Now installing" << endl;
system("start c:\\jre-8u291-windows-x64.exe");
Includes:
#include <iostream>
#include <atlstr.h>
#include <Windows.h>
#include <urlmon.h>
#include <stdio.h>
#include <stdlib.h>
#pragma comment(lib, "urlmon.lib")
using namespace std;
Output:
My code is a basic HelloWorld but fails to compile when I use cout<<endl.
I'm using Microsoft visual studio fresh download and created a console application for my first test project.
// Test1ConsoleApplication.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
#include <iostream>
//#include <ostream>
using namespace std;
int main()
{
string s = "hello world!!";
cout << "lets see: " << s << endl;
return 0;
}
It generates a
"C1001" at line 1.
Replacing "endl" with ""\n"" works though.
You don't need the precompiled header #include <stdafx.h> so you can safely get rid of it. Also get rid of using namespace std; because it pollutes the global namespace. Try something like this. There's no reason it shouldn't work.
#include <string>
#include <iostream>
using std::string;
using std::cout;
using std::endl;
int main()
{
string s = "hello world!!";
cout << "lets see: " << s << endl;
return 0;
}
In Visual Studio you can disable use of the precompiled header in the project settings.
I do not see what the problem is. Both options compile and execute for me.
RexTester cppOnline
// Test1ConsoleApplication.cpp : Defines the entry point for the console application.
//
//#include "stdafx.h"
#include <string>
#include <iostream>
//#include <ostream>
using namespace std;
int main()
{
string s = "hello world!!";
cout << "lets see: " << s << endl;
cout << "lets see: " << s << "\n";
return 0;
}
So idk what was causing the error but it was fixed after pasting imports to the "stdafx.h" header file and then delete them...
I am using the tensorflow c++ API in my code. And I found when I load image from files the image is NULL. Then I write a test code to find the reason.
Here is my test code:
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
//#include "tensorflow/core/public/session.h"
//#include "tensorflow/core/protobuf/meta_graph.pb.h"
int main()
{
Mat imgtry = imread("lena.jpg");
printf("%dx%d", imgtry.cols, imgtry.rows );
return 0;
}
When I comment tensorflow's header, the output value is 255x255, but once I uncomment the header, the output value is 0x0. Why ???
The problem seems change slightly after I revised the sequence of link library. At first, I link the tensorflow_cc and tensorflow_frameworok and then the opencv's libriries. Now, I put the tensorflow's libraries after the opencv and the let corresponding include directory as the same sequence. Then I can read image normally even uncomment the code in the above code area. But new porblem occured.
#include "opencv2/opencv.hpp"
#include "opencv2/imgcodecs.hpp"
//it's ok.
#include "tensorflow/core/public/session.h"
#include "tensorflow/core/protobuf/meta_graph.pb.h"
using namespace std;
int main()
{
cv::Mat img;
img = cv::imread("lena.jpg");
if(img.empty() == true) {
cout << "Error!" << endl;
exit(1);
}
cout << "ok!" << endl;
//uncomment this, the img is always emtpy!!!
// tensorflow::SessionOptions sessOptions;
// sessOptions.config.mutable_gpu_options()->set_allow_growth(true);
// auto session = tensorflow::NewSession(sessOptions);
// if(session == nullptr) {
// cout << "Could not create Tensorflow session." << endl;
// exit(1);
// }
return 0;
}
It's a known bug
Feel free to update this Community Wiki answer with Workaround / Solution / Bug status / Etc...
this is my code i am using vs2013. i have set dependencies and all the linkers but still my code compiles correctly but when cosole opens it says error initializing vm, unable to find native libraries
#include <iostream>
#include <voce.h>
#include <Windows.h>
#include <string>
#pragma comment(lib, "jvm.lib")
#pragma comment(lib, "jawt.lib")
using namespace std;
int main()
{
init("C:\\voce-0.9.1\\lib\\", false, true, "C:\\voce - 0.9.1\\lib\\gram", "digits.gram");`
string s;
// Speech recognition in C++
while (voce::getRecognizerQueueSize() > 0)
{
s = voce::popRecognizedString();
cout << "You said: " << s << endl;
}
return 0;
}