-
April 27th, 2014, 10:09 AM
#1
[RESOLVED] Convert From C# to Managed C++ and C++/CLI
Hi Iam tryin to convert my Digit To Words class from c# to VC++... And the following line I am facing trouble
String^ strNum;
String^ strNumDec;
String^ StrWord;
strNum = Convert::ToString(Num); // Num is Decimal Parameter
blah..blah...blah...
StrWord = ((double.Parse(strNum) == 1) ? " Rupee " : " Rupees ") + NumToWord((decimal)(double.Parse(strNum))) + ((double.Parse(strNumDec) > 0) ? (" and Paise" + cWord3((decimal)(double.Parse(strNumDec)))) : "");
Thanks
-
April 27th, 2014, 01:16 PM
#2
Re: Convert From C# to Managed C++ and C++/CLI
-
April 28th, 2014, 04:49 AM
#3
Re: Convert From C# to Managed C++ and C++/CLI
If what you posted is the actual code you tried to compile as C++/CLI, you're facing two syntactical issues:
While C# uses the dot operator for all sorts of class member access, C++/CLI uses that one for instance members of value types only. For instance members of reference types it uses -> instead, and :: for static members of both reference and value types.
Unlike C#, C++/CLI doesn't feature a keyword synonym for the System::Decimal type. So you'd need to write it with a capital D to directly refer to the actual type. (I assume you have a using namespace System; in effect, since otherwise you couldn't declare String variables without explicitly specifying the namespace either.)
This would lead to the following changes to your code line:
Code:
StrWord = ((double::Parse(strNum) == 1) ? " Rupee " : " Rupees ") + NumToWord((Decimal)(double::Parse(strNum))) +
((double::Parse(strNumDec) > 0) ? (" and Paise" + cWord3((Decimal)(double::Parse(strNumDec)))) : "");
Also, C-style casts as we have them here should generally be avoided. Here I'd suggest to at least use static_cast instead. Admittedly, that will make the code look even more ugly and make it harder to read. Why not simply parse to a Decimal directly using Decimal::Parse()??
And please use code tags when posting code.
Last edited by Eri523; April 28th, 2014 at 01:07 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
April 28th, 2014, 12:23 PM
#4
Re: Convert From C# to Managed C++ and C++/CLI
Thanks Eri...Your reply cleared me very well.
Thanks for all replies.
Thanks & Regards
Mahey
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|