Accessing variables with cout not working

Hello (first post),

Please help. I've been programming with C++ on Windows for years, but all of a sudden my code will not work. I was using Dev-C++, I'm now using Code::Blocks, although the error still persists. Here is my program:
#include <iostream>
using namespace std;
int main(void){
  int n=42;
  return 0;

Code::Blocks says it's returning 0xC0000005, which seems to be saying that I have no right to access n. But I should... right?

Using stdio.h and printf to display n works fine,
and just printing text with cout works too
Last edited on
Have you tried removing the "void" and just having int main() ?
I just tried that, still getting the same error.
Have you tried stepping through it with a debugger? Have you checked the md5 on your build of your compiler (e.g. MinGW)? It is possible that maybe the libraries you are linking to have some problems. At any rate, try stepping through with the debugger, and when it crashes, find the call stack to see what function(s) caused it to crash.
Thanks, it's working now. I think there was something wrong with the library I got from MinGW, I just updated/upgraded and now it's working.
Last edited on
Topic archived. No new replies allowed.