main.cpp:
#include <iostream>
#include <string>
using namespace std;
int main()
{
unsigned int m = (1<<31);
string s(m, 'a');
string s1(m, 'a');
string s2(m, 'a');
return 0;
}
main.c:
#include <stdio.h>
int main()
{
int a[1024*1024*100] = {0};
return 0;
}
结果:
taoge@localhost Desktop> g++ main.cpp
taoge@localhost Desktop> ./a.out
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create
Aborted (core dumped)
taoge@localhost Desktop> gcc main.c
taoge@localhost Desktop> ./a.out
Segmentation fault (core dumped)
taoge@localhost Desktop>