Click here to Skip to main content
16,005,120 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Logging data in MS-ACCESS......few problems!!! Pin
David Crow30-Jul-04 2:51
David Crow30-Jul-04 2:51 
GeneralRe: Logging data in MS-ACCESS......few problems!!! Pin
avenger_sb2530-Jul-04 8:28
avenger_sb2530-Jul-04 8:28 
GeneralNot able to set properties of newly developed Activex Control at run time Pin
samhita29-Jul-04 18:26
samhita29-Jul-04 18:26 
Generalfunction to determine the adminstrator and integration with a dialog based app Pin
Anonymous29-Jul-04 18:13
Anonymous29-Jul-04 18:13 
GeneralRe: function to determine the adminstrator and integration with a dialog based app Pin
Michael Dunn29-Jul-04 19:21
sitebuilderMichael Dunn29-Jul-04 19:21 
GeneralRe: function to determine the adminstrator and integration with a dialog based app Pin
User 58385229-Jul-04 19:21
User 58385229-Jul-04 19:21 
GeneralRe: function to determine the administrator and integration with a dialog based app Pin
David Crow30-Jul-04 2:54
David Crow30-Jul-04 2:54 
Generalstl string class in VS2003 Pin
User 58385229-Jul-04 16:57
User 58385229-Jul-04 16:57 
I am converting some of our projects from Visual Studio 6 to Visual Studio 2003
I have found that the following code gives different results from these compilers
In VS6 "Josh" is printed. in VS2003 nothing is printed.

If I trace into c_str() I can see that the correct pointer is returned to s. However between the call to TestFn() and printf the destructor of stl::string is called. This is for the temp object created when returning from TestFn(). In VS2003 a '\0' is inserted at the fist element in the buffer by this destructor. In VS6 this does not happen.

In VS2003 If I use the memory viewer I can see that s points to a \'0' followed by 'o' 's' 'h' '\0';
In VS6 the same things points to 'J' 'o' 's' 'h' '\0'

Can anyone explain why this is happening?

#include "stdafx.h"
#include <string>
using namespace std;

string globalString = "Josh";

string TestFn()
{
return globalString;
}

int main(int argc, char* argv[])
{
const char * s = TestFn().c_str();
printf(s);
return 0;
}
GeneralRe: stl string class in VS2003 Pin
Tim Smith29-Jul-04 17:20
Tim Smith29-Jul-04 17:20 
GeneralRe: stl string class in VS2003 Pin
User 58385229-Jul-04 17:28
User 58385229-Jul-04 17:28 
GeneralRe: stl string class in VS2003 Pin
palbano29-Jul-04 17:56
palbano29-Jul-04 17:56 
GeneralRe: stl string class in VS2003 Pin
paulb29-Jul-04 17:42
paulb29-Jul-04 17:42 
GeneralRe: stl string class in VS2003 Pin
User 58385229-Jul-04 17:45
User 58385229-Jul-04 17:45 
GeneralRe: stl string class in VS2003 Pin
John M. Drescher29-Jul-04 22:51
John M. Drescher29-Jul-04 22:51 
GeneralRe: stl string class in VS2003 Pin
User 58385229-Jul-04 23:48
User 58385229-Jul-04 23:48 
GeneralRe: stl string class in VS2003 Pin
Tim Smith30-Jul-04 4:27
Tim Smith30-Jul-04 4:27 
GeneralRe: stl string class in VS2003 Pin
User 58385230-Jul-04 15:02
User 58385230-Jul-04 15:02 
GeneralSetting up Tab Controls Pin
Tyrus18229-Jul-04 16:25
Tyrus18229-Jul-04 16:25 
GeneralRe: Setting up Tab Controls Pin
alex.barylski29-Jul-04 17:44
alex.barylski29-Jul-04 17:44 
GeneralManually adding resources to rc2 file Pin
paulb29-Jul-04 16:22
paulb29-Jul-04 16:22 
GeneralRe: Manually adding resources to rc2 file Pin
John M. Drescher29-Jul-04 17:30
John M. Drescher29-Jul-04 17:30 
GeneralRe: Manually adding resources to rc2 file Pin
V.29-Jul-04 20:44
professionalV.29-Jul-04 20:44 
GeneralQuestion on OCX Pin
prgrmr29-Jul-04 15:29
prgrmr29-Jul-04 15:29 
QuestionCPropertySheet - how to abort OnOK? Pin
Max Santos29-Jul-04 14:36
Max Santos29-Jul-04 14:36 
AnswerRe: CPropertySheet - how to abort OnOK? Pin
Ryan Binns29-Jul-04 18:24
Ryan Binns29-Jul-04 18:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.