How to work on stream string in C++/CX RRS feed

  • Question

  • Hi, I am having WinRT Component in my project, where I need to pass "const char *". that is image thumnail data. so I have taken String^ property for my component object[which can be used in c#]. and assigning String^ property from C# code like following:

    using (StreamReader reader = new StreamReader(fileStream))
                                imgThumb = reader.ReadToEnd();

    Then I want to convert the String^ to const char* [Note: const char* is an image data]. Please provide me solution. I don't have much coding experience in C++/CX.

    I have tried following code to convert String^ to const char *".  but it doesn't worked.

    char* narrow( const wstring& wstr )
    			//const char *cstr = wstr.c_str();
    			ostringstream stm ;
    			const ctype<char>& ctfacet =
    				use_facet< ctype<char> >( stm.getloc() ) ;
    			for( size_t i=0 ; i<wstr.size() ; ++i )
    				stm << ctfacet.narrow( wstr[i], 0 ) ;
    			string str = stm.str();
    			char* c = new char [str.size()+1];
    			//			strcpy(c, str.c_str());
    			return c;

    Please help me. thanks in advance...

    Pallam Madhukar Windows Phone Developer

    Tuesday, March 4, 2014 10:59 AM

All replies