0

I have a listBox in Visual C++ 2008, and I want the first line convert to string. So first, I select the first line

listBox1->SetSelected( 0, true );

And afterwards, I want to convert it to string

string t = listBox1->SelectedItems[ 0 ];

Which results in an error:

error C2440: 'initializing' : cannot convert from 'System::Object ^' to 'std::basic_string<_Elem,_Traits,_Ax>'

How can I convert it?

user4512345632
  • 23
  • 1
  • 2
  • 4

1 Answers1

1

Definitely look into using the marshal_as template method. It handles all the nasty conversions for you internally.

MikeP
  • 7,829
  • 33
  • 34