<ra**********@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
Hi All,
I am using .net first time.In my windows form VC7 application, on a
click of button, I am assigning text of TextBox to STL string varibale.
Using this code-
private: System::Void FindValuesButton_Click(System::Object * sender,
System::EventArgs * e)
{
string fileLoc ;
fileLoc= CD_location->Text->ToString();
......
}
I am getting error-
'initializing' : cannot convert from 'System::String __gc *' to
std::basic_string<_Elem,_Traits,_Ax>'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
I think this is due to manage class problem. Could anyone tell me, how
can I assign text box value to STL string. Can I use STL string in
VC++.net application.
Regards,
Rachit
Rachit,
I believe you can use the properties Char and Length of System::String
to pull out the individual characters and place them in a wchar_t array then
assign your STL string to the array. However note 2 things: First, you will
need to append an '\0' character to the end of the wchar_t array; Second,
from your listing of the error, the STL string template is using <charbut
the System::String is made up of unicode characters. Try declaring your
string as std::basic_string<wchar_t>... I'm a bit rusty but I would try
something along the lines of the following
std::basic_string<wchar_tfileLoc;
wchar_t buffer[255]; //size it appropriately
for(int i = 0; i < CD_location->Text->Length; ++i)
{
buffer[i] = CD_location->Text->Char[i];
}
buffer[CD_location->Text->Length] = wchar_t('\0');
fileLoc = buffer;
HTH - M