how to fix this CString not working

I have a form with a label.

I use the openfile dialog to get a filename and save it to the labeltext.
I then need to get the label text and build a new filename from it.

int rtn;
string oldname;


OpenFileDialog^ sfd = gcnew OpenFileDialog();
sfd->Filter = "Pose Files|*.pz2|All files (*.*)|*.*";
if( sfd->ShowDialog() != System::Windows::Forms::DialogResult::OK )
{
return;
}
myfile->Text = sfd->FileName;
oldname = myfile->Text;
}


This gives me a build error.
In the old c++ 6 I used Cstring for the variable oldname but it seems to be unavailable in VS 2010.

any help appreciated.

1) This is not C++. This is C++/CLI which is a different language.
2) Without the error you are getting and such small snippet of code, not many people will be able to help.
3) Standard C++ classes and managed CLI stuff are not getting along. Try System::String instead of std::string.
Note that CString is part of MFC:

http://en.wikipedia.org/wiki/Microsoft_Foundation_Class_Library

What you're using here is .NET:

http://en.wikipedia.org/wiki/.NET_Framework

it comes with System::String. You need the Copy() function in order to copy the string:

https://msdn.microsoft.com/en-us/library/system.string.copy%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

Simple assignment would copy the pointer.
OK, thanks

I did the program originally in Microsoft Visual studio 6 using C++
This version is using Visual Studio Express 2010 - the C++ from it.


I added #include<string>

what do I include for the system::string instead ?

This version is using Visual Studio Express 2010 - the C++ from it.

But what you've posted still is not c++.

I added #include<string>

yep that's the one. then you can instantiate like this:

std::string myString("hello");

BUT that's assuming you'll be switching to pure c++. otherwise miniipaa's number 3.
Last edited on
Topic archived. No new replies allowed.