Click to See Complete Forum and Search --> : Conversion error? help pls (C++.Net)


kennis
January 25th, 2005, 09:29 AM
i little bit new to this i hope u guys can help me out, i got this:

#include <string>
using namespace std;

private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
string a;
a=this->txt1->Text; //error line!!
}

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'System::String __gc *' (or there is no acceptable conversion)

thanks so much!

GoobTheNoob
January 25th, 2005, 09:58 AM
String is a managed class thus it must be declared as a pointer in C++.

String *pA;

pA = this->txt1->Text;

NoHero
January 25th, 2005, 10:00 AM
Try this instead:


string a;
a = this->txt1->get_Text();


/ 18 posts to go

kennis
January 25th, 2005, 10:38 AM
#2 i add the pointer but it says
error C2440: '=' : cannot convert from 'System::String __gc *' to 'std::string *'

#3 that the almost same error as before
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'System::String __gc *' (or there is no acceptable conversion)

more help pls!

PaulJJJ
January 27th, 2005, 08:40 AM
GoobTheNoob has right.
The followwing should work.
----
String *pA;

pA = this->txt1->Text;
-----

Be careful of the case of "String*" the S is as upperCase.

they
January 27th, 2005, 08:09 PM
Replace:

#include <string>
using namespace std;


With:

using namespace System;

--------------------------------------------------------

String* is part of the "System" namespace. You do not need to call "std" or include <string>.