Strange crashes using cout or Strings

Having been playing with the tutorials a bit, I'm getting very odd crashes for code that should be fine (I've played with both C and Java before). The following code describes my issues:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
using namespace std;

int main () {
  
  //Works
  cout << "Hello World\n";
  
  //Works
  char c[] = "Hello World\n";
  cout << c;
  
  //Crashes on cout
  int i = 2;
  cout << i;
  
  //Crashes on the string declaration
  string str = "Hello World\n";
  cout << str;
  
  return 0;
}


There's nothing in there at all that should be causing a crash - the only possibly exception being that my string declaration is wrong for C++, but it seems fine.

I'm running on MinGW 4.8.1, which is all I can think of being at fault. However, I've used it quite happily for C for a long time.

Thoughts?
The code is right!
I compiled with Clang in Mac OS X
Try Microsoft Visual Studio!
The code is fine:
http://ideone.com/5cpbzF

Have you tried reinstalling your compiler?

If you are on a 64-bit system, I recommend using nuwen MinGW:
http://nuwen.net/mingw.html
>Have you tried reinstalling your compiler?

I went through and did an upgrade of MinGW (from version 4.7.something), but I could try a proper clean and reinstall at some point.

>If you are on a 64-bit system, I recommend using nuwen MinGW

That does the job, thank you! Perhaps one day I'll even work out what the cause of the crashing was - still very odd it only affected C++ and not C.
You have to completely remove old installations before upgrading to new ones - files can be deleted in newer versions but simply copying over the old version won't delete the files, and you'll confuse the compiler.
I used mingw-get, and you'd have hoped it wouldn't end up making a mess of itself on update, given it's the entire point of the program!
There seems to be a difference between using gcc or g++ when using mingw. You can use gcc but there are extra options required.
BitRat wrote:
There seems to be a difference between using gcc or g++ when using mingw. You can use gcc but there are extra options required.
That was not the issue here ;)
Topic archived. No new replies allowed.