Error in opening .exe release file in eclipse - c++

When i run the .exe release file it shows some kind of awkward error in my IDE.
And when I try to run from outside the IDE as an appilcation it terminates as soon as it opens without showing any output.
I am using Eclipse and MinGw
This is the error message my ide shows.
And i guess there is nothing wrong with my code.
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World" << endl;
cout << "hello Again" << endl;
return 0;
}

This is not an error, you are viewing the contents of the exe file which is not human-readable, but binary data. The output from your application is in the 'Console' window at the bottom of the screen.

Related

How to debug console app in QtCreator (Windows/macOS)

I'm working on a console app in QtCreator 9. I need user inputs at some point, so I use a few std::cin in my c++ code.
The integrated "application output" pane does not accept any input though. I tried to switch to the Terminal by checking the right option (Projects->Run->Run in terminal). This works only when the app is launched with the Run button, but not with the Start Debugging of Startup Project button, which then falls back to the application output pane.
Any workaround ?
edit : I need interactive input, so a workaround with command line argument is not an option.
You can use the QTextStream class in Qt to get input from the terminal. You can redirect stdin to QTextStream using the following code:
#include <QTextStream>
#include <iostream>
int main(int argc, char *argv[])
{
QTextStream in(stdin);
QString input;
std::cout << "Enter some text: ";
in >> input;
std::cout << "You entered: " <<
input.toStdString() << std::endl;
return 0;
}
This way you can use the "Start Debugging of Startup Project" button and get the input from the terminal

SYCL program working using VS Debugger but not when running the .exe

I am trying to build and run a simple SYCL program from this book. Here it is:
#include <CL/sycl.hpp>
#include <iostream>
using namespace sycl;
const std::string secret {
"Ifmmp-!xpsme\"\012J(n!tpssz-!Ebwf/!"
"J(n!bgsbje!J!dbo(u!ep!uibu/!.!IBM\01"
};
const auto sz = secret.size();
int main(int argc, char* argv[]) {
queue Q;
char* result = malloc_shared<char>(sz, Q);
std::memcpy(result, secret.data(), sz);
Q.parallel_for(sz, [=](auto& i) {
result[i] -= 1;
}).wait();
std::cout << result << "\n";
return 0;
}
I am using Visual Studio 2019 and I am compilating with Intel oneAPI DPC++ 2022. If I run the Visual Studio Debugger, everything is working, I am obtaining as output:
"Hello World! I'm sorry, Dave. I'm afraid i can't do that. - HAL"
But if I am executing the .exe file that I just have built from the command prompt, nothing is happening... The program is executing itself, nothing is given as output, and I receive no error either. I tried to put some printf everywhere to see where to problem could come from. If I put a printf right just after "queue Q;" I wouldn't be able to see it when I run the .exe file.
From what I have read the problem comes from the initialization of my object Q. I replaced "queue Q;" by "queue Q(default_selector{});" but it didn't solve the problem.
EDIT : I have simply reduced the code to the following:
#include <CL/sycl.hpp>
#include <iostream>
using namespace sycl;
int main(int argc, char* argv[]) {
std::cout << "Beginning of the program.\n";
queue Q; // The problem appears to come from this line
std::cout << "End of the program.\n";
system("pause");
return 0;
}
Here is the output when I am launching the program in the Visual Studio Debugger:
> Beginning of the program.
> End of the program.
>
> Sortie de C:\Users\...\test.exe (processus 8108). Code : 0.
> Press any key to continue . . .
Here is the output when I am calling the .exe from the command prompt:
> C:\Users\...\Release>test.exe
> Beginning of the program.
>
> C:\Users\...\Release>
I have noticed that during the short time when the program is running in the command prompt (something like one second), I saw that the program Windows Problem Reporting ran in the Task Manager. Than it vanished as soon as the program apparently finished to compute.
EDIT 2 : Here is what happens if I am looking for the device used. With the following code:
#include <CL/sycl.hpp>
#include <iostream>
using namespace sycl;
int main(int argc, char* argv[]) {
default_selector device_selector;
std::cout << "default_selector has been defined.\n";
auto defaultQueue = queue(device_selector);
std::cout << "default_queue has been defined.\n";
std::cout << "Running on " << defaultQueue.get_device().get_info<info::device::name>() << "\n";
system("pause");
return 0;
}
I get this output from the Visual Studio debugger:
> Beginning of the program...
> default_selector has been defined.
> default queue has been defined.
> Running on Intel(R) Core(TM) i5-3337U CPU # 1.80GHz
> Press any key to continue...
And this when I am executing the .exe from the commande prompt (doing this in administrator or not doesn't change anything):
> C:\Users\...\Release>test.exe
> Beginning of the program...
> default_selector has been defined.
>
> C:\Users\...\Release>
The answer has been brought by the Intel Developer Software Forums.
Although the compiler has been well installed on my machine, the oneAPI environment had not be configured yet. This is why it couldn't work when running the .exe in the Windows command prompt.
I had to run the batch file setvars.bat that was at the adress C:\Program Files (x86)\intel\oneAPI then it worked!

unable to open files c++

I'm really struggling at the moment, originally had other issues with eclipse itself, that seems to have been resolved. Code looks right to me (compared to example code for loading files) however I'm not able to load anything as the error I put in is always triggered. No building errors atm. What am I doing wrong? Tried with both eclipse (mac) and Code::blocks (win vm), both seem to be having issues. the data files themselves are in the same folder as the .cpp file.
#include <iostream>
#include <string>
#include <math.h>
#include <fstream>
using namespace std;
int main() {
cout << "Choose which data file to load (1-4)" << endl;
int file;
cin >> file;
ifstream data;
switch (file) {
case 1:
data.open("dataSet1.txt");
case 2:
data.open("dataSet2.txt");
case 3:
data.open("dataSet3.txt");
case 4:
data.open("dataSet4.txt");
}
if (!data) {
cerr << "File not Loaded" << endl;
return -1;
}
string FullData[61];
for (int i=0; i=60; i++){
data >> FullData[i];
cout << FullData[i] << endl;
}
return 0;
}
EDIT: Got the program to stop showing the error, and it seems to be loading the files, however my assign/display loop doesn't seem to be working now as it displays only the last data point over and over again.
the data files themselves are in the same folder as the .cpp file
Being in the same folder as the .cpp is not important, the dataset files should be in the same folder as the compiled binary program.
It can also be that there is a working directory setting that does not point on the directory where your dataset files are. All that is being passed into the open member function is a string which means that interpreting what that string means depends on the environment settings.
Same issue. In my case as #Gluk36 pointed, the problem was the working directory settings.
In that case, you must deselect "Use default settings" and set where the binary is. I attach you a screenshot for your reference from eclipse CDT 4.9 under linux.
You must have break statement after each case
like:
case1://something;
break;
and you must close the stream with close() function
data.close();

Visual Studio in debug mode restarts automatically after an exception is thrown (C++)

I'm working on a big C++ project which I haven't created, but the following short code fully represents a problem which I'm faced with:
#include <string>
#include <iostream>
int main(int argc, char **argv){
using namespace std;
try{
string str;
str = "r";
double d = stod(str);
cout << "'stod' worked! d = " << d << endl;
}
catch (invalid_argument){
cout << "I'm in 'catch'\n";
}
cout << "I'm after 'try-catch'\n";
cin.get();
cin.get();
return 0;
}
If I launch the code without debugger, everything works fine and as expected it gets into the catch-scope and then main() proceeds.
If I use the debugger, Visual Studio under 32-bit configuration restarts immediately or under 64-bit configuration I get a message: "The debugger's worker process (msvsmon.exe) unexpectedly exited. Debugging will be aborted."
I'm using VS2013 Ultimate on Windows 8.1 Professional.
Due to this post:
msvsmon.exe crashed when debugging
I have already installed Update 4. I have no breakpoints. In DEBUG->EXCEPTIONS the reset was done.
I also do not understand, what msvsmon.exe is. The Google-search combines it with remote debugger which confuses me a little bit, because I'm using the local debugger, at least I press each time the 'Local Windows Debugger' button.
Could anybody help me out?

C++ read from file

when I try to debug this code to read from a file and display it, the console screen comes and goes quickly and I don't understand why it's doing this. Can anyone help me please?
#include "Questions.h"
#include <iostream>
using namespace std;
const int MAXITEMS = 10;
struct quiz
{
string question;
string anser;
};
int main ()
{
string str;
ifstream ifs("Questions2.txt.txt");
getline (ifs,str);
cout << "first line of the file is " << str << ".\n";
return 1;
}
You should click some breakpoints in VS window.Then when you press F5,it will pause at breakpoint, then it will run continue until you press F5 again.
Or,if you make sure your code is correct.You can press Ctrl+F5.This means "Run Without Debug".
This situation,your program will run to end and suggest you "Press any key to continue".
Sorry for my bad english. Hope you can understand.
try with ifs.open, and then assure yourself by using ifs.is_open () function with an if and an error code, I always use it and it worth
and of course, use a breakpoint before the return (clicking it or using system ("pause")
You can try including a pause function. This way it will display your data and then wait for a response. I've included the function I typically use.
void myPause()
{
cout << " Press enter to continue... ";
char blank[8];
cin.getline(blank,8);
cin.sync();
}
Unless you run with some breakpoints, Visual Studio will close the window after the program terminates.
If you want the window to stay on the screen, use Debug->Start without debugging
Or, add a breakpoint at return 1;
Press F10 instead of F5. By pressing F10, you can go line by line