Solved

CList pointing to a structure

Posted on 1997-10-20
1
578 Views
Last Modified: 2012-08-13
Is it possible to create a CList pointing to a structure, which contains several items of CStrings??
If anyone knows the answer, possible to show an example?

Thanks a zillion
elv
0
Comment
Question by:elv
1 Comment
 
LVL 5

Accepted Solution

by:
yonat earned 50 total points
ID: 1171820
Sure it is possible. Here is an example:

#include <afxtempl.h> // for CList
#include <afx.h> // for CString

struct MyStruct {
  int i;
  CString s1;
  CString s2;
};

int main()
{
  CList <MyStruct,MyStruct> myList;

  // add elements to the list
  MyStruct st;
  st.i = 17;
  st.s1 = "foo";
  st.s2 = "bar";
  myList.AddTail(st);
  // ...

  // get elements
  POSITION pos = myList.GetHeadPosition();
  while (pos != NULL)      {
    st = myList.GetNext(pos);
    // do stuff with st
  }

  return 0;
}

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Converting to C# also VS2015 5 117
C++ Class Serialization, Encapsulation and Formatted Output 8 54
max float value 3 25
Copy output image from TWindowsMediaPlayer 6 22
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now