locked
string vector to add in Combo Box. RRS feed

  • Question

  • Dear WinTechies,

    I am a newbie to STL and MFC, I need bit clues for my app to build.

    I have std::vector<std::string>xyz; and to this I need to add it in a Combo Box, to add I am using AddString(),but AddString() takes only string.

    So pls help me suggesting how to add the above variable to the combo box,any specific conversions required..its a request..

    Thanks all..

    Wednesday, July 6, 2011 5:38 AM

Answers

  • I am a newbie to STL and MFC, I need bit clues for my app to build.
    I have std::vector<std::string>xyz; and to this I need to add it in a Combo Box, to add I am using AddString(),but AddString() takes only string.
    So pls help me suggesting how to add the above variable to the combo box,any specific conversions required..its a request..

    You'd need loop around the vector, and AddString each item, something
    like this:

    for ( vector<string>::const_iterator it = xyz.begin();
        it != xyz.end();
        ++it )
    {
        cb.AddString( it.cstr() );
    }

    or this (depending on which version compiler you have)

    for each ( const string & it in xyz )
    {
        cb.AddString( it.cstr() );
    }

    Dave

    • Marked as answer by aditz Wednesday, July 6, 2011 12:10 PM
    Wednesday, July 6, 2011 6:28 AM

All replies

  • I am a newbie to STL and MFC, I need bit clues for my app to build.
    I have std::vector<std::string>xyz; and to this I need to add it in a Combo Box, to add I am using AddString(),but AddString() takes only string.
    So pls help me suggesting how to add the above variable to the combo box,any specific conversions required..its a request..

    You'd need loop around the vector, and AddString each item, something
    like this:

    for ( vector<string>::const_iterator it = xyz.begin();
        it != xyz.end();
        ++it )
    {
        cb.AddString( it.cstr() );
    }

    or this (depending on which version compiler you have)

    for each ( const string & it in xyz )
    {
        cb.AddString( it.cstr() );
    }

    Dave

    • Marked as answer by aditz Wednesday, July 6, 2011 12:10 PM
    Wednesday, July 6, 2011 6:28 AM
  • Thanks Dave for giving the clue.I'll work on it.
    Wednesday, July 6, 2011 6:35 AM
  • Thanks Dave it worked.Getting the expected output..
    Wednesday, July 6, 2011 7:11 AM