Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:39:49+00:00 2026-06-04T01:39:49+00:00

I am working with MFC and I have this class: class CUnit { private:

  • 0

I am working with MFC and I have this class:

class CUnit
{
private:
    CString name;
    CString init;
    CString chp;
    CString rhp;
    CString condition;
public:
    CUnit(void);
    ~CUnit(void);
    void setName( CString str );
    void setInit( CString str );
    void setCHP( CString str );
    void setRHP( CString str );
    void setCond( CString str );
    CString getName() const;
    CString getInit() const;
    CString getCHP() const;
    CString getRHP() const;
    CString getCond() const;    
    bool operator< ( CUnit ) const;
};

CUnit::CUnit(void)
{
}


CUnit::~CUnit(void)
{
}

bool CUnit::operator< ( CUnit unit ) const
{
    return !( this->init < unit.init );
}

void CUnit::setName( CString str )
    {
        name = str;
    }
void CUnit::setInit( CString str )
    {
        init = str;
    }
void CUnit::setCHP( CString str )
    {
        chp = str;
    }
void CUnit::setRHP( CString str )
    {
        rhp = str;
    }
void CUnit::setCond( CString str )
    {
        condition = str;
    }
CString CUnit::getName() const
{
    return name;
}
CString CUnit::getInit() const
{
    return init;
}
CString CUnit::getCHP() const
{
    return chp;
}
CString CUnit::getRHP() const
{
    return rhp;
}
CString CUnit::getCond() const
{
    return condition;
}

I get the values from Editboxes successfuly but when I insert them in a set<CUnit> when I get the CString values back I only get the first letter. I tried with a vector but it’s all the same.
I fill the set like so:

vector<CUnit> units;
CUnit unit;
CEdit *edit;
CString str;
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_NAME1));
edit->GetWindowText(str);
unit.setName(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_INIT1));
edit->GetWindowText(str);
unit.setInit(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_CHP1);
edit->GetWindowText(str);
unit.setCHP(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_RHP1));
edit->GetWindowText(str);
unit.setRHP(str);
edit = reinterpret_cast<CEdit *>(GetDlgItem(IDC_COND1+i));
edit->GetWindowText(str);
unit.setCond(str);
units.push_back(unit);

And I use this to check if everything is ok:

vector<CUnit>::iterator pos = units.begin();
str = *pos->getName();
SetDlgItemText(IDC_NAME2, str );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:39:51+00:00Added an answer on June 4, 2026 at 1:39 am

    you may use as follows:

        str = *(pos->getName());
    

    or

        str = (*pos).getName();
    

    wish help you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this MFC dialog program I am working with. The dialogs are
I am working on a program built in MFC. I have this weird situation
I have been working with C++ and Win32 (non MFC/ATL) I am playing around
I'm working on a bug where I have an MFC application that does weird
I have a working iterator for MFC CObList - BaseMFCIter . It works for
I'm working on a win32/MFC project. I have a custom CListCtrl control that I
Keyboard Enter key not working in MFC Dialog Box ? I have one MFC
So I'm working on a class project that uses MFC. I never had to
I have an MFC app which I have been working on for a few
I'm localizing an MFC app into Japanese, and have the resources working right. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.