somebody please help me..
can you tell me about struct in C++..
please give me example and explaination..

Recommended Answers

All 4 Replies

Member Avatar for jencas

getFirstMatch(google("cpp reference struct"));

getFirstMatch(google("cpp reference struct"));

tq..

A struct can look like this. You will call the struct for sorting in this case, mysort1 as a third argument in a sort, so you pass one a1 and a2 to the struct.

struct mysort1
  {
  bool operator () ( const std::string& a1, const std::string& b1 )
    {
    std::stringstream c1( a1 );
    std::stringstream c2( b1 );
    double d1, d2;
    c1 >> d1;
    c2 >> d2;
    return d1 < d2;
    }
  };

A struct is a simple user-defined data type that can contain other (user defined or standard) datatypes. For example, if you wanted to create a struct of golfer names and scores:

struct SGolfer
{
  //struct members go here
  char   * _szName;
  int        _iScore;
};

This can now be called like this:

int main()
{
   SGolfer Golfer1;
   strcpy(Golfer1._szName, "Tiger Woods");
   Golfer1._iScore = 80;
   //and as an array, and pointer
   SGolfer * pGolfer2;
   SGolfer x[25];
}

Methods and operator overloading may also be used, like the above post mentions. But I think that's a bit outside the scope of your understanding since you are just being introduced to structs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.