Error with running graphics porgrams in codeblocks - c++

I am using codeblocks 17.2 for c++ and i am struggling to successfully get an output while running a graphics program. I have added all the linker settings and files successfully but there is still a problem. When i run a basic graphics program, It compiles and runs properly but there is a blank output with this line
Process returned -1073741819 (0xC0000005) execution time : 2.891 s
Press any key to continue.
this is my code
#include<iostream>
#include<graphics.h>
#include<conio.h>
using namespace std;
int main()
{
int gd = DETECT;
int gm;
initgraph(&gd,&gm, "C:\\TC\\BGI");
circle(300,300,50);
closegraph();
getch();
}

Related

Error in Visual Code while running a C++ Code

I was trying to run a C++ program in VS Code.
Program:
#include<iostream>
#include<math.h>
using namespace std;
int main(){
int n;
cout<<"enter the no "<<endl;
cin>>n;
int ans=0,i=0;
while(n!=0){
int bit=n&1;
ans= (bit * pow(10, i) ) + ans;
n=n>>1;
i++;
}
cout<<ans;
}
This program isn't working in my pc. But whenever I try to run same program in online compiler on another pc, It works fine.
Like If I enter the input as 6, then it prints 109 instead of 110.
Why is the program not working properly on my PC?
I also tried to debug to check the program but Debugger prints the output to Debug Console even though ExternalConsole is set to true. From Debug Console, It doesn't take the input. Giving the error, Unable to perform this action because process is running.
Why my vscode prints on Debug Console instead of ExternalConsole?

Graphics program doesn't show output?

I have 32 bit windows 7 system, in turbo c++ graphics.h is activated, my code compiled successfully, linked successfully but doesn't run and does not show any output how can I get it to work?
#include <iostream.h>
#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm,"C:\TC\BGI");
putpixel(25,25,WHITE);
closegraph();
return 0;
}
it is showing following:
Linking ...\SOURCE\NONAMEOO.EXE

SDL ignores std::cin

I started learing SDL using visual studio 2015, and I am following a video tutorial.
I already have everything setup.
This tutorial is all about drawing a blank window. After drawing the window the author adds a std::cin to take in an integer so that the window does not quit immediately.
The problem is that I have done the same exact thing but my window quits instantly.
This is my main.cpp:
#include"SDL.h"
#include<iostream>
#include"MainGame.h"
int main(int argc, char *args[]) {
using namespace std;
MainGame maingame;
maingame.run();
cout<<"Enter any key: "
int a;
cin>>a;
return 0;
}
This same thing works in the video. What am I doing wrong here?
It seems like visual studio isn't told to pay attention to the console, so it just throws away std::cin.
Try replacing it with:
SDL_Delay(1000); // do nothing for 1 second

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?

runtime errors not showing up in debugger

I've got a couple of programs written in CPP which crash. Some are graphics based, others are command line. Usually they include a while loop and crash after a few minutes.
I attached them to GDB and compiled and executed in Dev C++, and they don't show any sign of crashing. I can run them for hours on end and there are no problems. But once intake it out of that environment they crash in a couple of minutes.
For example I have this code:
#include <cstdio>
#include <cstdlib>
int main (int argc, char * args[]){
char sysstr[100];
if (argc<2){
printf("No .java file given...");
}else{
sprintf(sysstr,"java %s",args[1]);
try {
system(sysstr);
}
catch (int lol){
}
}
return 0;
}
It runs fine within DevC++, but outside windows tells me after it has finished that it stops working.
Help?