I'm not sure, but it seems to be a problem with string class and how it manages memory. str retains the value and its memory address until just before the main starts excecuting and loose them as soon as excecution enters main.
Try the same program with char* and you would see no such problem.
Ankur
|