Home > Software engineering >  [for] about m_strArray. GetAt error (2)
[for] about m_strArray. GetAt error (2)

Time:10-04

Sun Xin recently in learning c + + tutorial, programming the phone book, in the menu display telephone number, use m_strArray records, GetAt () v output, recorded a total of four phone Numbers, the code is as follows,
The problems: 1, 2, 4 have no bug, save 3 a, come again appear problem, please help see what reason,



 void CMenu2View: : OnChar (UINT nChar, UINT nRepCnt, UINT nFlags) 
{
//TODO: add the message handler code and/or invoke the default
CClientDC dc (this);
If (0 x0d==nChar)
{
If (0==+ + m_nIndex)
{
M_menu. CreatePopupMenu ();
The GetParent () - & gt; The GetMenu () - & gt; AppendMenuW (MF_POPUP, (UINT) m_menu m_hMenu, _T (" PhoneBook "));
The GetParent () - & gt; DrawMenuBar ();//redraw window
}
M_menu. AppendMenuW (MF_STRING IDM_PHONE1 + m_nIndex, m_strLine. Left (m_strLine. Find (' ')));
M_strArray. Add (m_strLine);
M_strLine. Empty ();
Invalidate ().
}
The else
{
M_strLine +=(TCHAR) nChar;
Dc. TextOutW (0, 0, m_strLine);
}
The CView: : OnChar (nChar nRepCnt, nFlags);
}


Void CMenu2View: : OnPhone1 ()
{
//TODO: add the command handler code
CClientDC dc (this);
Dc. TextOutW (0, 0, m_strArray GetAt (0));
}


Void CMenu2View: : OnPhone2 ()
{
//TODO: add the command handler code
CClientDC dc (this);
Dc. TextOutW (0, 0, m_strArray GetAt (1));
}


Void CMenu2View: : OnPhone3 ()
{
//TODO: add the command handler code
CClientDC dc (this);
Dc. TextOutW (0, 0, m_strArray GetAt (2));
}


Void CMenu2View: : OnPhone4 ()
{
//TODO: add the command handler code
CClientDC dc (this);
Dc. TextOutW (0, 0, m_strArray GetAt (3));
}

CodePudding user response:

Header files define the wrong, sorry, no problem,
Correct:
# define IDM_PHONE1 201
# define IDM_PHONE2 202
# define IDM_PHONE3 203
# define IDM_PHONE4 204

Error:
# define IDM_PHONE1 201
# define IDM_PHONE2 202
# define IDM_PHONE4 203
# define IDM_PHONE3 204

CodePudding user response:

CodePudding user response:

About whether he is suitable for programming is very simple test:
On a newspaper or magazine articles, for a period of about 1000 words in Word input again, after losing to refer to the following answer:

A. there are more than 10 words or punctuation
B there is no words or punctuation mistakes and dare to bet for this
No words or punctuation errors and C fonts and layout fully consistent with the original
D print on the translucent paper and check the same original overlap, and feel very with a sense of accomplishment

A is not suitable for programming (reason: typing accuracy is low, careless)
B junior programmer (reason: typing accuracy high, careful and meticulous, confident, understand the whole Angle of half Angle concept)
C senior programmer (reason: in the B on the basis of understanding the font and layout is also an important factor of computer to print, but compared to D paranoid enough, strives for perfection, the results can verify)
D software project manager (reason: to be able to give convincing for project detailed requirements to the pole and typical test cases, users almost pick is not at fault, major!)

If want to from A to B, to my resources http://download.csdn.net/detail/zhao4zhong1/4084259 download "for programmers keyboard practice"

CodePudding user response:

So obvious, it is crossing the line.

You cut the figure, you see is's assertion that the index of legitimacy.

CodePudding user response:

M_strArray. Add (m_strLine);//
Use:
Const int GetSize ();
Check a few?
  • Related