我现在有个double的数值要在listbox中显示,怎样转换成符合LPCTSTR后用listbox.AddString()显示啊?!求教!!请代码展示!!!

解决方案 »

  1.   


    CString csDValue;
    csDValue.Format(_T("%f"), dValue);
    listbox.AddString(csDValue);
      

  2.   

    CListBox::AddString
    This method adds a string to a list box. If the list box was not created with the LBS_SORT style, the string is added to the end of the list. Otherwise, the string is inserted into the list, and the list is sorted. If the list box was created with the LBS_SORT style but not the LBS_HASSTRINGS style, the framework sorts the list by one or more calls to the CompareItem method.int AddString( 
    LPCTSTR lpszItem ); 
    Parameters
    lpszItem 
    Points to the null-terminated string that is to be added. 
    Return Value
    The zero-based index to the string in the list box. The return value is LB_ERR if an error occurs; the return value is LB_ERRSPACE if insufficient space is available to store the new string.Use InsertString to insert a string into a specific location within the list box.Example
    // The pointer to my list box.
    extern CListBox* pmyListBox;// Add 10 items to the list box.
    CString str;
    for (int i=0;i < 10;i++)
    {
      str.Format(_T("item string %d"), i);
      pmyListBox->AddString( str );
    }//不会了先查MSDN
      

  3.   

    二楼,请问我现在是double x,我想让它在listbox内显示怎么处理?
      

  4.   

    //例子都给你了啊
    str.Format(_T("item string %d"), i);这个的%i改成%lf或者%f,i为double类型的变量