[Solved] Help getting getText() into System::String^

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
jimburnettva
Posts: 13
Joined: Fri Feb 19, 2010 5:07 pm
Contact:

[Solved] Help getting getText() into System::String^

Post by jimburnettva »

I'm tired and maybe someone else can see something I'm missing.



/* This doesnt work. */
core::stringw pname =txtID->getText();
std::stringstream ss;
ss << pname.c_str() << endl;



/*
Docs for GetBytes()
http://msdn.microsoft.com/en-us/library ... S.71).aspx
*/

cli::array<Byte>^sendBytes = Encoding::ASCII->GetBytes( ss.str() + "," + ship->getPosition().X + "," + ship->getPosition().Y + "," + ship->getPosition().Z );
udpClient->Send( sendBytes, sendBytes->Length );

Errors:
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(33) : see declaration of 'std::operator +'
1>CLRSpaceGame.cpp(241): error C2784: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const irr::f32'
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\string(19) : see declaration of 'std::operator +'
1>CLRSpaceGame.cpp(241): error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_iterator<_Elem,_Traits,_Alloc>' from 'const irr::f32'
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(434) : see declaration of 'std::operator +'
1>CLRSpaceGame.cpp(241): error C2784: 'std::_String_const_iterator<_Elem,_Traits,_Alloc> std::operator +(_String_const_iterator<_Elem,_Traits,_Alloc>::difference_type,std::_String_const_iterator<_Elem,_Traits,_Alloc>)' : could not deduce template argument for 'std::_String_const_iterator<_Elem,_Traits,_Alloc>' from 'const irr::f32'
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xstring(293) : see declaration of 'std::operator +'
1>CLRSpaceGame.cpp(241): error C2784: 'std::_Array_iterator<_Ty,_Size> std::operator +(_Array_iterator<_Ty,_Size>::difference_type,std::_Array_iterator<_Ty,_Size>)' : could not deduce template argument for 'std::_Array_iterator<_Ty,_Size>' from 'const irr::f32'
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(2068) : see declaration of 'std::operator +'
1>CLRSpaceGame.cpp(241): error C2784: 'std::_Array_const_iterator<_Ty,_Size> std::operator +(_Array_const_iterator<_Ty,_Size>::difference_type,std::_Array_const_iterator<_Ty,_Size>)' : could not deduce template argument for 'std::_Array_const_iterator<_Ty,_Size>' from 'const irr::f32'
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(1929) : see declaration of 'std::operator +'
1>CLRSpaceGame.cpp(241): error C2784: 'std::reverse_iterator<_RanIt> std::operator +(_Diff,const std::reverse_iterator<_RanIt> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const irr::f32'
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(1323) : see declaration of 'std::operator +'
1>CLRSpaceGame.cpp(241): error C2784: 'std::_Revranit<_RanIt,_Base> std::operator +(_Diff,const std::_Revranit<_RanIt,_Base> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'const irr::f32'
1> C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xutility(1136) : see declaration of 'std::operator +'
1>CLRSpaceGame.cpp(241): error C2676: binary '+' : 'std::basic_string<_Elem,_Traits,_Ax>' does not define this operator or a conversion to a type acceptable to the predefined operator
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
Last edited by jimburnettva on Tue Sep 07, 2010 11:53 pm, edited 1 time in total.
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

This puts the pointer address in ss which is probably not what you want.
jimburnettva wrote:

Code: Select all

core::stringw pname =txtID->getText();
std::stringstream ss; 
ss << pname.c_str() << endl;
this works:

Code: Select all

  IGUIStaticText * text = guienv->addStaticText(L"Test", recti(0,0,0,0));

  std::string a = core::stringc( text->getText() ).c_str();

  std::stringstream ss;

  ss << a.c_str() << std::endl;

  std::cout << ss.str();
Never take advice from someone who likes to give advice, so take my advice and don't take it.
jimburnettva
Posts: 13
Joined: Fri Feb 19, 2010 5:07 pm
Contact:

Post by jimburnettva »

I still get the same errors with:


std::string a = core::stringc( txtID->getText() ).c_str();
std::stringstream ss;
ss << a.c_str() << std::endl;
cli::array<Byte>^sendBytes = Encoding::ASCII->GetBytes( ss.str() + "," + ship->getPosition().X + "," + ship->getPosition().Y + "," + ship->getPosition().Z );
udpClient->Send( sendBytes, sendBytes->Length );
jimburnettva
Posts: 13
Joined: Fri Feb 19, 2010 5:07 pm
Contact:

Post by jimburnettva »

i'm trying to convert getText to type "T"

Such as this (but this doesn't worky)


template <class T>
T getName (std::stringstream ss)
{
T result;
result = ss.string();
return (result);
}
jimburnettva
Posts: 13
Joined: Fri Feb 19, 2010 5:07 pm
Contact:

FIX

Post by jimburnettva »

Figured it out.


std::string a = core::stringc( txtID->getText() ).c_str();
String^ s = gcnew String(a.c_str());


Works like a charm!
Post Reply