Changing x86 to x64 affects my LNK1168 Error - c++

So I created a code in C++ using visual studio and I was learning about making classes and using methods/functions. The program was working fine until I wrote the using namespace std; and suddenly trying to run my code I got a LNK1168 error and I tried everything to fix it.
I made sure that no tasks were running, and I saved it and closed it and opened it back up to run it again and still no matter what I did, the LNK1168 error pops back up.
I then switched from debugging x86 to debugging x64 and my code works normally with the x64.
Does this matter? If so why, if not then what should I do?
#include<iostream>
// did not include the using namespace std; because that's when my issue started
// not sure if it had something to do with it
class Player
{
public:
int x, y;
int speed;
void movin(int xa, int ya)
{
x += xa * speed;
y += ya * speed;
}
};
int main()
{
Player player;
player.movin(1, 1);
std::cout << "apples are tasty"; // this is to make sure my code prints something
std::cin.get();
return 0;
}
I tried looking up youtube videos but nothing helps! Oddly enough the x64 works but not the usual x86? Does this affect my code or how I compile my code? Would it make things run slower? I am confused.
I tried looking at the Windows Help site after clicking the error and nothing helps. Does anyone know?

LNK1168 Means your executable is still running when you try to compile the code. Close the app, and then compile.

Related

How do I graph data in c++?

I am trying to make a graph using graphics.h in c++. I was following a tutorial on youtube. It seems that either due to the age of the video (perhaps the syntax has changed slightly?) or a problem on my end; I cannot even get a separate window for my graph to open. I am in completely uncharted waters for me as the limit of my coding knowledge is what you would expect to learn from a first-semester coding class. I am using DEV C++ and am compiling using "TDM-GCC 4.9.2 32-bit Release" (because the 64 bit release gives me an error in "Makefile.win" that scares me) and my program exits with a return value of 3221225477. What am i doing wrong?
#include"graphics.h"
#include<math.h>
#include<conio.h>
#include<iostream>
using namespace std;
int main() {
initwindow(800,600);
int x,y;
line(0,300,getmaxx(),300);
line(400,0,400,getmaxy());
float pi=3.14159;
for(int i=-360;i<=360;i++){
x=(int)400+i;
y=(int)300-sin(i*pi/100)*25;
putpixel(x,y,WHITE);
}
getch();
closegraph();
return 0;
}
According to your issue and exit-code, the return value in hex is 0xC0000005 or STATUS_ACCESS_VIOLATION. But most developers didn't even bother to learn out-dated legacy API and I can not help you to find the exact line (use debugger, it shows you the exact line, still not the reason).
But to answer your question in the title, well, according to what free framework one uses (Qt or XWidget), the method differs, for Qt (which I would recommend) simply override paint-event and use QPainter renderer to show your QPath data.
Don't reinvent the wheel (or render-system in this case), your course and/or book may soon introduce you to one of the mentioned frameworks.

Visual Studio CPP No Entry

I'm writing a cpp app for some while now. A few hours into the day made a small change did a build to test it and to my surprise , the build executed and nothing happened , it didn't stop executing it had a process running.
so I stopped it. and this is what I have tried.
Restrating my PC- Same Result
Making a breakpoint after the entry point. - Same Result
breakpoint didn't even hit which makes me think that the entry point just does not work.
Making a syntax error - it didn't compile and didn't run
which means my program did compile and did run before.
Completly undoing everything I did after the last running build - Same Result. it worked before but i guess not anymore
Changing my entry point from WinMain to int main() -
cmd window was created but no signs of code executing.
Doing std::cout on the first line(with cmd window) - Same Result
The only thing that worked was commenting the whole file with the entry point and just writing :
#include <iostream>
int main() {
int i;
std::cout << "hello";
std::cin >> i;
}
Anyone knows what can make such a weird behavier ?
You probably have an infinite loop in some static initialisation code.
If you hit pause in the debugger it will show you where the problem lies.

Weird compiling error with CodeBlocks - c++

that's my first use to code block but it hasn't gone fine ,, i face a really weird problem
i cant even describe it so i will just tell you what's happened.
the problem is that the ide dont compile my project even if the code were correct
its just open a new tab that called "iostream" and the console window appears but empty
why do that happens ?
look to the code which the ide face a problem while compiling it ,, simplest code ever
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
and this is the compiling results...
thats all..
will codeblocks stop annoying me ?
This line is not valid syntax
usingnamespace std;
Those are two separate keywords
using namespace std;
And since you are just starting C++, Lesson 1: Don't do that.

How to work with Dev C++

I am new in programming. but i know turbo C & i can work with it. But how to work on Dev C++?
i means 1.How to Compile & 2. How to Run. I have Windows so if anyone help me with proper example than it will be great.
Dev c++ is very simple! To do the basic, Open you file, compile and run using the menu Execute!
However, if u are starting something new now, I would suggest you consider using eclipse. It is not so easy in the first days but the long term gain is giant!
I would like to improve my answer... I suggested that you should consider using eclipse. I still think that eclipse is great. Furthermore, I had had some problems with the old version of dev c++. After reading the comment of #Orwell (which provided facts that I didn't know), I checked the new version and the issues that I had had before disappeared. So, the big picture of dev c++ is that it is a program that works well and it is very simple. There is a cost to start using eclipse!
Example:
#include <iostream>
using namespace std;
int fibonacci(int n){
if(n==1)return 0;
if(n==2)return 1;
if(n>=3)return fibonacci(n-1)+fibonacci(n-2);
}
int main(){
//
int n =10;
cout << "The element of the Fibonacci series is " << fibonacci(n) << "\n";
return 0;
}

Crash in windows XP with very simple gtk+cairo program

I am developing a Gtk application using gtkmm on Windows Vista with Visual Studio 2005. The application works fine on the development machine but I have received crash reports after it has been run on Windows XP machines (both Service Pack 2 and 3). I distribute the app with the directory structure described in http://live.gnome.org/gtkmm/MSWindows and it had given me no problems so far.
The crash gives no error messages except for Windows asking whether I want to report the error.
In order to solve the problem, I tried to compile the program against different versions of gtkmm (a recent stable version gtkmm-win32-devel-2.16.0-4 and an older version gtkmm-win32-devel-2.10.11-1) but the problem persisted.
I hunted down the problem to a call to window->create_cairo_context() inside the on_expose_event of a Gtk::DrawingArea. When I commented out this call, the problem would disappear. So I wrote the following minimal program, which still crashes:
#include <gtkmm.h>
#include <iostream>
class MyWindow : public Gtk::Window {
bool on_expose_event(GdkEventExpose* event) {
std::cout << "expose" << std::endl;
Glib::RefPtr<Gdk::Window> window = get_window();
if(window) {
std::cout << "win" << std::endl;
std::cout << "Get cairo" << std::endl;
Cairo::RefPtr<Cairo::Context> cr = window->create_cairo_context();
std::cout << "Get cairo done" << std::endl;
} else {
std::cout << "no win" << std::endl;
}
return true;
}
};
int main (int argc, char *argv[]) {
Gtk::Main m(argc,argv);
MyWindow w;
m.run(w);
return 0;
}
This minimal app may run and display the window without problem, but if I move the window off the screen limits or if I minimize/maximize it enough times (thus triggering calls to on_expose_event), it will eventually crash. It may also be the case that it won't crash the first time, but it will crash after restarting the app and triggering multiple calls to on_expose_event as described above. One thing I've noticed is that the app crashes after printing "Get cairo done". When I comment out the call to create_cairo_context, the problem dissapears, so I'm pretty sure there is something wrong with this line.
The error happens on clean installed Windows XP machines. I have tested both apps (original and minimal) on a colleague's notebook, which also has Windows XP, but it doesn't crash there. I suppose there is some dependency that is available/up to date in our computers but not in the computers where the application crashes. I have updated DirectX and installed Visual Studio C++ 2005 Redistributable on one of the problematic machines, but the problem persists.
The original app, which draws a graph on the DrawingArea, doesn't necessarily crash the first time either. It may work fine the first time after rebooting, but is more prone to fail the second time.
I am thinking about compiling and testing with MinGW to see if that solves the problem. I'll also try to compile a debug version and try to use a debugger. I have suspected the version of gdi32.dll might have something to do, seeing that libcairo-2.dll depends on this dll according to Dependency Walker, but until now it's just an speculation. Other than that, I'm out of ideas.
I'll be trying these ideas for the time being. Hopefully someone has more suggestions or knows what is going on with the code above.