C++/help!!

Advertisement


Question
i have created:
struct gateType {
      char type[5];
      int input1PinOrder;
      int input2PinOrder;
      int outputPinOrder;
      };
      
struct gateType myGates[8][3];

but in the main program when i write:
myGates[j][i].type="and";
the compiler says: incompatible types in assignment! what should i do??

Answer
Hello maki, thank you for the question.

If you want to be able to directly assign a value to a string, the std::string class has the = operator overloaded for that purpose. Otherwise, it is illegal. The wasy to do this is with a call to strcpy to copy the string into the array:

strcpy(myGates[j][i].type, "and", sizeof(char)*5));

This copies over 5 bytes from the source, to the destination.

strcpy is located in the file string.h

I hope this information was helpful.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.