Newbie: Add 2 strings together

P

Paul Hemans

I am trying to have a label show the X and Y positions of the mouse, but I
am getting bogged down with string handling

void MyForm::OnMouseMove(MouseEventArgs *e){

// Display the x position

string ss;

ss = e->X.ToString();

ss += " ";

ss += e->Y.ToString();

m_poLabel->Text = ss;

}



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



Thanks
 
P

pvdg42

Paul Hemans said:
I am trying to have a label show the X and Y positions of the mouse, but I
am getting bogged down with string handling

void MyForm::OnMouseMove(MouseEventArgs *e){

// Display the x position

string ss;

ss = e->X.ToString();

ss += " ";

ss += e->Y.ToString();

m_poLabel->Text = ss;

}



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



Thanks
Try something like this...

System::String^ fun = L"Done!";

fun += L" I'm a genius!";

label2->Text = fun;

Works fine here.
 
P

Paul Hemans

What does the ^ mean?

When I compile I get:
'^' : incompatible with '/clr:blush:ldSyntax' command line option

How do I turn this option off?
 
P

Paul Hemans

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

on the line
ss = e->X.ToString();

Any ideas?
 
P

pvdg42

Paul Hemans said:
What does the ^ mean?

When I compile I get:
'^' : incompatible with '/clr:blush:ldSyntax' command line option
Perhaps I've made an invalid assumption here. The code I sent is C++/CLI in
VS 2005. If you're using an earlier version of Visual Studio, it won't work.
BTW, ^ is a handle in C++/CLI.
Please tell us which version of Visual Studio you're using.
 
B

Ben Voigt

pvdg42 said:
Perhaps I've made an invalid assumption here. The code I sent is C++/CLI
in VS 2005. If you're using an earlier version of Visual Studio, it won't
work.
BTW, ^ is a handle in C++/CLI.
Please tell us which version of Visual Studio you're using.

VS2005, because VS2003 didn't have an oldSyntax option, it always used
oldSyntax.

The option is in the project settings -- under "Common Language Runtime
Support", try "/clr" instead of "/clr: oldSyntax".

The basic problem is while C# has a string keyword which maps to
System.String, C++/CLI does not. In C++, string is either undefined or
finds the Standard C++ library class std::string, which is not the same as a
..NET string. Use String with a capital S, no other changes to your original
program should be necessary.
 
P

Paul Hemans

I turned off the oldSyntax setting and the rest of the program blew up.

I have to say learning c++ is a nightmare (particularly regarding strings).

In Foxpro I would do :

label.text = trans(e.X) + " " + trans(e.Y)

I do understand that Foxpro is a high level language and that a comparison
shouldn't be made but after 2 days I still can't add a couple of strings
together it really makes you wonder. Maybe I am thick, or maybe C++ has been
reworked so many times that only gurus can make a program with it.

Can you recommend a VS2005 book that teaches this stuff well? I found one on
2003 but I am glad I didn't buy it because apparently a lot has changed
between versions.
 
P

pvdg42

Paul Hemans said:
I turned off the oldSyntax setting and the rest of the program blew up.

I have to say learning c++ is a nightmare (particularly regarding
strings).

In Foxpro I would do :

label.text = trans(e.X) + " " + trans(e.Y)

I do understand that Foxpro is a high level language and that a comparison
shouldn't be made but after 2 days I still can't add a couple of strings
together it really makes you wonder. Maybe I am thick, or maybe C++ has
been reworked so many times that only gurus can make a program with it.

Can you recommend a VS2005 book that teaches this stuff well? I found one
on 2003 but I am glad I didn't buy it because apparently a lot has changed
between versions.

Here's one we've found useful for MFC and CLI.

http://he-cda.wiley.com/WileyCDA/HigherEdTitle/productCd-0764571974,courseCd-CX0400.html
 
C

chris

I know this problem:
You can't define a string like this "string ss;", must be "String
*ss".


"Paul Hemans дµÀ£º
"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top