Mohsen Sarkar
Mohsen Sarkar

Reputation: 6030

How to convert String^ to String in C++ CLI?

Whenever I try to directly assign a String variable to another String variable I get error found no suitable conversation.
So is there a way to convert String^ pointer to a non-pointer struct String ?

I want :

System::String a = System::String('X',256);

I don't want :

System::String^ a = %System::String('X',256);

Upvotes: 1

Views: 4376

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283713

No, there is not, because as Hans pointed out in a comment, System::String is immutable. You cannot assign it. You can only associate a handle with an entirely new System::String object.

BTW

System::String^ a = %System::String('X',256);

is incorrect, it should be

System::String^ a = gcnew System::String('X',256);

Upvotes: 3

Oswald
Oswald

Reputation: 31675

Use System::String a('X', 256);.

Upvotes: -1

Related Questions