constant area ?? Return values are simply copies of the original variable your wanting to return. If it's not assigned immediately, you have no way of reaching the value again because the original variable and all local variables declared are deallocated off the stack and no longer used. If you were to return char *p it would NOT work because line had been deallocated and placed out of scope. In order to fix this you would have to move outside of the stack which is where local variable are stored and you'd have to use the new operator or malloc to allocate to the heap.
EDIT: Ugh..Someone else explain, I don't know if I explained correctly :/
I am trying do a system program.
in this program the user can format his disks and another things...
but when I use system code
for example: #include <stdlib.h>
system("format d:")
the computer is giving alert ! :
are you sure to format d,
please press enter if you are sure...
then the user press enter .
But I dont want to show this to user.
I want to my program press enter himself and format.
dont show this to the user.
& i have also tried this code
system( "echo.|format d: >nul 2>&1" );
but it does not work for drives & only work for usb devices.....
plz help me....
nanger
The value assigned to p is typically stored in a CPU register or on the stack.
If you are asking about the array of characters it points to... it just references the std::string's internal buffer. (All STL implementations do this -- though I don't think they are required to do so.) That's why wonky stuff like the following work:
Just keep in mind that anything that modifies the string may cause the buffer to be reallocated (meaning that anything you previously got from ::c_str() is not safe to consider valid to cache anywhere.)