locked
String error with RC

    Question

  • with CP my code is working, but now with RP i get a error "Unhandled exception at 0x000007FC1AEC9EA0 (vccorlib110d.dll)"

    Platform::String^ Add(char ch,Platform::String^ string)

    {

    return (string+ch)

    }

    what other ways can we add char and platform::string ?

    Friday, June 01, 2012 11:48 PM

Answers

  • std::wstring to_wstring( const std::string & txt )
    {
    	std::wstring wstr;
    	wstr.resize( txt.size() + 1 );	// Allocate space for trailing 0
    	
    	size_t charsConverted;	// Convert mult-byte-str to wide-char-string
    	errno_t err= ::mbstowcs_s( &charsConverted, (wchar_t * )wstr.data(), wstr.size(), txt.data(), txt.size() );
    	wstr.pop_back();	// Discard trailing \0
    
    	return wstr;
    }
    
    std::wstring to_wstring( char ch )
    {
    	std::string txt ( &ch, 1 );
    	return to_wstring( txt );
    }
    
    
    Platform::String^ addChar( Platform::String^ platformString, char ch ) 
    {	
    	std::wstring	stdChar = to_wstring( ch );
    	Platform::String^ platChar= ref new String( stdChar.c_str() );
    	
    	return platChar->Concat( platformString, platChar );
    }
    	
    
    	MyTextBlock->Text= addChar( L"Tiger", '7' );

    This code resulted in Tiger7 being placed in MyTextBlock.

    Anybody have something better?

    • Proposed as answer by Jesse Jiang Monday, June 04, 2012 9:04 AM
    • Marked as answer by Jesse Jiang Wednesday, June 20, 2012 8:47 AM
    Saturday, June 02, 2012 6:00 PM