|
hshan 2022 wrote:
</div>switch (switch_on)
{
case 1:
{
Sedan Mercedes("Sedan");
Mercedes.marka = "Mercedes";
Mercedes.model = "A klasa";
Mercedes.hp = 145;
Mercedes.v = 2.1;
Mercedes.cena = 156000;
Sedan* wsk_sedan;
wsk_sedan = &Mercedes;
wsk_sedan->buduj();
}
case 2:
{
Sedan BMW("Sedan");
BMW.marka = "BMW";
BMW.model = "d531i";
BMW.hp = 166;
BMW.v = 2.5;
BMW.cena = 188770;
Sedan* wsk_sedan;
wsk_sedan = &BMW;
wsk_sedan->buduj();
}
Don't you want to add the breaks at the end of these cases?
|
|
|
|
|
if you will not add the break with case then they will execute either both after one to one
|
|
|
|
|
not relevant as i wanted to replace that method anyway my man
but yes i forgot about that
|
|
|
|
|
If you were going to give descriptions of many cars then the switch/case logic is not a good choice. Each time you add another car you need to change / compile / redistribute your application. Your descriptions of cars and their features should be outside the program.
Look at the different kinds of ways that data can be stored, including but not limited to: tables, files, arrays and lists.
You want to choose one that works long term. How many different types of cars will you include? How often will you make changes including corrections, additions and deletions? How do you want to make those updates? All these ideas need to be considered before you can choose the best solution.
|
|
|
|
|
Hi,
I need to generate the following XML codes. And Iam using VS2015.
<TALLYMESSAGE xmlns:UDF="TallyUDF">
<VOUCHER VCHTYPE="Sales" ACTION="Create">
<VOUCHERTYPENAME>Sales</VOUCHERTYPENAME>
<ALLLEDGERENTRIES.LIST>
<REMOVEZEROENTRIES>No</REMOVEZEROENTRIES>
<ISDEEMEDPOSITIVE>Yes</ISDEEMEDPOSITIVE>
<LEDGERFROMITEM>No</LEDGERFROMITEM>
<LEDGERNAME>Customer 1</LEDGERNAME>
<AMOUNT>-5000</AMOUNT>
</ALLLEDGERENTRIES.LIST>
</VOUCHER>
</TALLYMESSAGE>
For That from our website quick answers, I received the following codes in C#.
[XmlRoot(ElementName="ALLLEDGERENTRIES.LIST")]
public class ALLLEDGERENTRIESLIST {
[XmlElement(ElementName="REMOVEZEROENTRIES")]
public string REMOVEZEROENTRIES { get; set; }
[XmlElement(ElementName="ISDEEMEDPOSITIVE")]
public string ISDEEMEDPOSITIVE { get; set; }
[XmlElement(ElementName="LEDGERFROMITEM")]
public string LEDGERFROMITEM { get; set; }
[XmlElement(ElementName="LEDGERNAME")]
public string LEDGERNAME { get; set; }
[XmlElement(ElementName="AMOUNT")]
public int AMOUNT { get; set; }
}
[XmlRoot(ElementName="VOUCHER")]
public class VOUCHER {
[XmlElement(ElementName="VOUCHERTYPENAME")]
public string VOUCHERTYPENAME { get; set; }
[XmlElement(ElementName="ALLLEDGERENTRIES.LIST")]
public ALLLEDGERENTRIESLIST ALLLEDGERENTRIESLIST { get; set; }
[XmlAttribute(AttributeName="VCHTYPE")]
public string VCHTYPE { get; set; }
[XmlAttribute(AttributeName="ACTION")]
public string ACTION { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName="TALLYMESSAGE")]
public class TALLYMESSAGE {
[XmlElement(ElementName="VOUCHER")]
public VOUCHER VOUCHER { get; set; }
[XmlAttribute(AttributeName="UDF")]
public string UDF { get; set; }
[XmlText]
public string Text { get; set; }
}
Is It possible to convert this From C# to Visual C++ 2015.
My heartiest thanks for all helps
Always Thank To Richard & Victor & Other Superiors, those who are having kind hearts.
Thank Again
|
|
|
|
|
You posted this question in QA[^] asking for C# code.
You've now copied someone else's C# code and want it converted to C++.
Make your damn mind up!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hi Richard Deeming, Sorry & Thank for the advise and the reason is Visual C++/CLR doesn't support LINQ.
I do remember all your advises are powerful & good. Your replies helped many times while I get struck.
Thank Again !
|
|
|
|
|
|
|
Stop focusing on C# code and start focusing on learning to write your own C++ XML code from scratch. You'll learn a lot more that way.
|
|
|
|
|
Hi,
Iam using Vs2015, While I try to Open a file using OpenFileDialog, Iam receiving the error
"Unhandled exception of type" System.AccessViolationException" occoured in system.windows.forms.dll
Additional information: Attempted to read or write protected memory.This is often an indication other memory is currupt.
My Codes
System::Windows::Forms::OpenFileDialog^ MyFileOpenDialog = gcnew System::Windows::Forms::OpenFileDialog();
MyFileOpenDialog->Title = "Select Your Excel Test File";
MyFileOpenDialog->InitialDirectory = "C:\\";
MyFileOpenDialog->Filter = "Excel Files (*.xls)|*.xls|All files (*.*)|*.*";
MyFileOpenDialog->FilterIndex = 2;
MyFileOpenDialog->RestoreDirectory = true;
if (MyFileOpenDialog->ShowDialog() == System::Windows::Forms::DialogResult::OK) {
MyExcelFile = MyFileOpenDialog->FileName;
}
I cannot understand my mistake !
Thanks For the helps!
Richard pls. advise me! Thank again !
modified 5-Oct-21 2:59am.
|
|
|
|
|
|
Thank Victor
|
|
|
|
|
How do I convert array to list?
array<System::Byte>^ My1DArray = gcnew array<System::Byte>(100);
to
List<System::Byte>^ temp
temp = My1DArray.ToList();
Update:
I am currently using a for loop to copy data 1 by 1, if there's no other faster way ,i'll stick with this for now . Thanks!
array<System::Byte>^ My1DArray = gcnew array<System::Byte>(100);
int^ bytesToRead = gcnew(int);
*bytesToRead = SerialPort->BytesToRead;
SerialPort->Read(My1DArray, 0, *bytesToRead);
SerialPort->DiscardInBuffer();
List<System::Byte>^ temp = gcnew List<System::Byte>;
int^ counter = gcnew (int);
for (*counter = 0; *counter < *bytesToRead; (*counter)++) {
temp->Add(My1DArray[*counter]);
}
modified 11-Jun-21 1:53am.
|
|
|
|
|
why do you care about any "other faster way"?
How long is/are the array(s) to be converted? How often are you going to convert it/them?
|
|
|
|
|
Why are you using int's through handles and gcnew?
Why don't you just say
Int32 bytesToRead = 0;
Int32 counter = 0;
??
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi,
i made a library in c++/cli and beside a c# program calling it. Everything works fine when i compile on any cpu or x64 on my pc (x64os/x64proc). But if i compile for x86, c# part works fine, but when i use the c++/cli part i get the error "could not load file or assembly .... incorrect format" . I use user32.lib in the c++/cli, is it possible the problem come from here ?
---- Edit
I think it's ok, i activated copy reference to output project but i'm not sure it was that.
modified 30-May-21 17:11pm.
|
|
|
|
|
When you get a message like that, one project is compiling for either 32 or 64 bit and the other project is compiling for the opposite.
If the target is "Any CPU", a project will compile so that if the code runs on a 64-bit machine, it'll run as a 64-bit process, and if on a 32-bit machine, as a 32-bit process.
To solve this, make sure both projects build as either x64 or x86. Which depends on your requirements, but both projects have to build targeting the same thing.
|
|
|
|
|
how do you copy the bytes of a managed variable to another managed variable? memcpy doesn't work since my arguments are not the correct type for memcpy
#include "string.h"
float^ f = gcnew (float);
unsigned int^ temp = gcnew(unsigned int);
*temp = 0;
*temp = _byte3;
*temp = (*temp << 8U) + _byte2;
*temp = (*temp << 8U) + _byte1;
*temp = (*temp << 8U) + _byte0
pin_ptr<float> pinPtr_FloatVal = &(*f);
pin_ptr<unsigned int> pinPtr_UintVal = &(*temp);
memcpy_s(pinPtr_FloatVal , 4U, pinPtr_UintVal , 4U);
modified 28-May-21 8:32am.
|
|
|
|
|
|
Hello, I am trying to memcpy two managed values. The link provided seem to be for unmanaged to managed?
Could you show an example how to achieve this? Thanks!
|
|
|
|
|
|
The link that Victor gave you shows how to get a pointer to a managed object in order to copy data into it. So all you need is two such pointers in order to copy managed to managed.
|
|
|
|
|
Thank you very much Richard for elaborating a bit on this! I have solved my problem !
|
|
|
|
|
//Assuming int is on 4 bytes
typedef union u
{
int i;
byte b[4];
} U;
U x;
x.b[0] = 0 // Put first byte here
x.b[1] = 0 // second byte here, etc.
// Then use x.i as an integer
// Keep in mind that on Intel CPUs, integer values are represented in memory in reverse order.
// This means that hex value 0x11223344 will be represented in memory as 0x44, 0x33, 0x22, 0x11
// This is called little-endian vs. big-endian representation.
// There can be CPUs that uses the other convention.
// Make a small test project and play around with some values etc.
|
|
|
|