locked
CStringArray or std::vector? RRS feed

  • Question

  • I am new in VC++, and would like to know the choice between CStringArray and std::vector. I am doing the CString operation. Any ideas about comparing between them for CString operation, such as performance, flexibility, and so on? Any articles and any hyperlinks are great.

    Thanks.

    Friday, March 30, 2012 5:05 PM

Answers

  • On 30/03/2012 19:05, FugersonHall wrote:

    I am new in VC++, and would like to know the choice between CStringArray and std::vector. I am doing the CString operation. Any ideas about comparing between them for CString operation, such as performance, flexibility, and so on? Any articles and any hyperlinks are great.

    I'd suggest std::vector<CString>.
    std::vector is a standard container, and it "plays well" also with an ATL/MFC class like CString.

    std::vector has some advantages like a smarter more efficient growing policy (i.e. std::vector uses geometric growth vs. CStringArray's arithmetic growth).
    Moreover, being an STL container, std::vector works well in the rest of the STL "ecosystem", like STL algorithms (finding, sorting, etc.).

    Giovanni

    • Proposed as answer by Yi Feng Li Wednesday, April 4, 2012 3:37 AM
    • Marked as answer by Yi Feng Li Friday, April 6, 2012 3:16 AM
    Friday, March 30, 2012 10:10 PM

All replies

  • Leaping into MFC is quite a jump for one new to VC++.  Perhaps you have past experience in C++?  Anyway, I think that you may find std::vector much easier to work with when you plug it into the standard algorithms and other parts of the standard library.
    Friday, March 30, 2012 6:04 PM
  • On 30/03/2012 19:05, FugersonHall wrote:

    I am new in VC++, and would like to know the choice between CStringArray and std::vector. I am doing the CString operation. Any ideas about comparing between them for CString operation, such as performance, flexibility, and so on? Any articles and any hyperlinks are great.

    I'd suggest std::vector<CString>.
    std::vector is a standard container, and it "plays well" also with an ATL/MFC class like CString.

    std::vector has some advantages like a smarter more efficient growing policy (i.e. std::vector uses geometric growth vs. CStringArray's arithmetic growth).
    Moreover, being an STL container, std::vector works well in the rest of the STL "ecosystem", like STL algorithms (finding, sorting, etc.).

    Giovanni

    • Proposed as answer by Yi Feng Li Wednesday, April 4, 2012 3:37 AM
    • Marked as answer by Yi Feng Li Friday, April 6, 2012 3:16 AM
    Friday, March 30, 2012 10:10 PM
  • Hi,

    Would you mind letting me know the result of the suggestions? If you need further assistance, feel free to let me know. I will be more than happy to be of assistance.

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, April 4, 2012 3:38 AM