Click here to Skip to main content
15,917,328 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralSTL deque container question Pin
YaronNir1-Sep-03 3:59
YaronNir1-Sep-03 3:59 
GeneralRe: STL deque container question Pin
ZoogieZork1-Sep-03 4:20
ZoogieZork1-Sep-03 4:20 
GeneralRe: STL deque container question Pin
YaronNir1-Sep-03 4:21
YaronNir1-Sep-03 4:21 
GeneralRe: STL deque container question Pin
ZoogieZork1-Sep-03 4:24
ZoogieZork1-Sep-03 4:24 
GeneralRe: STL deque container question Pin
YaronNir1-Sep-03 4:29
YaronNir1-Sep-03 4:29 
GeneralWrapping Popup Menus Pin
Neal Stublen1-Sep-03 3:32
Neal Stublen1-Sep-03 3:32 
GeneralRe: Wrapping Popup Menus Pin
Neville Franks1-Sep-03 10:49
Neville Franks1-Sep-03 10:49 
GeneralString pointers (using stl) Pin
RChin1-Sep-03 2:52
RChin1-Sep-03 2:52 
Now, maybe its because its Monday, or maybe I truely am a dumbass; But I've got a bit of a problem code involving string pointers.

Let me explain: I've got a function that constructs a string and returns:
LPCTSTR CSomeClass::GetSerialString()
{
	std::ostringstream strstream;
	strstream<<	std::setfill((TCHAR)'0')<<\
				std::setw(5)<<m_nSerial;
	strstream<<std::flush;

	//
	// this string should now be 5 characters long.
	ASSERT( (strstream.str()).length() == 5 );	

	return (strstream.str()).c_str(); //<-- contains the correct string characters}
}


Whenever this function is called using the following code:

string strSerial;
strSerial = GetSerialCodeString(); //<-- strSerial is gibberish


The strSerial variable points to an invalid string array, even though at the point of tracing, the GetSerialString function contains the correct string.
Can someone explain why the LPCTSTR return value gets destroyed?


I Dream of Absolute Zero



GeneralRe: String pointers (using stl) Pin
Joaquín M López Muñoz1-Sep-03 3:01
Joaquín M López Muñoz1-Sep-03 3:01 
GeneralRe: String pointers (using stl) Pin
RChin1-Sep-03 5:58
RChin1-Sep-03 5:58 
GeneralIcons in the application bar Pin
Piero B1-Sep-03 2:40
Piero B1-Sep-03 2:40 
GeneralRe: Icons in the application bar Pin
Trollslayer1-Sep-03 4:15
mentorTrollslayer1-Sep-03 4:15 
GeneralRe: Icons in the application bar Pin
Anonymous2-Sep-03 4:27
Anonymous2-Sep-03 4:27 
GeneralMAPI Pin
ranjjj1-Sep-03 2:09
ranjjj1-Sep-03 2:09 
GeneralRe: MAPI Pin
Vitali Halershtein1-Sep-03 2:19
Vitali Halershtein1-Sep-03 2:19 
GeneralRe: MAPI Pin
ranjjj1-Sep-03 2:29
ranjjj1-Sep-03 2:29 
GeneralRe: MAPI Pin
Vitali Halershtein1-Sep-03 2:35
Vitali Halershtein1-Sep-03 2:35 
GeneralRe: MAPI Pin
ranjjj1-Sep-03 3:13
ranjjj1-Sep-03 3:13 
GeneralRe: MAPI Pin
Vitali Halershtein1-Sep-03 3:29
Vitali Halershtein1-Sep-03 3:29 
GeneralRe: MAPI Pin
ranjjj1-Sep-03 3:33
ranjjj1-Sep-03 3:33 
GeneralRe: MAPI Pin
ranjjj1-Sep-03 3:36
ranjjj1-Sep-03 3:36 
GeneralRe: MAPI Pin
Vitali Halershtein1-Sep-03 4:01
Vitali Halershtein1-Sep-03 4:01 
GeneralRe: MAPI Pin
ranjjj1-Sep-03 19:27
ranjjj1-Sep-03 19:27 
GeneralRecursive to iterative. Pin
1-Sep-03 1:53
suss1-Sep-03 1:53 
GeneralRe: Recursive to iterative. Pin
Joaquín M López Muñoz1-Sep-03 2:50
Joaquín M López Muñoz1-Sep-03 2:50 

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.