0

I know that there are a lot of Google answers out there for this topic, but I keep getting an error in my code.

In a GUI using Visual Studio in C++, I declared a struct in Form1.h:

  struct char_build {
       string name; 
  } user; 

But when I try to retrieve text from a Text Box like

 user.name = textBox1->Text; 

There's an error with managed vs. unmanaged strings, and a String ^ isn't able to go into the struct.

Any ideas of the best way to retrieve input in the Text Box and use it in the struct? Thanks!

m00nbeam360
  • 1,357
  • 2
  • 21
  • 36
  • Can u please try String^ instead of string... – NREZ Jul 11 '13 at 06:11
  • Thanks for the reference, chris, I'll check it out and close the question if that solves it for me. I've seen that answer before, but was curious if anyone knew of a simpler solution or if that was it. Thanks! – m00nbeam360 Jul 11 '13 at 06:17

1 Answers1

0

I do this by first converting to a wstring, then to string using the iterator constructor:

wstring temp(textBox1->Text->Data());
user.name(temp.begin(), temp.end()); 
McGarnagle
  • 101,349
  • 31
  • 229
  • 260