zoukankan      html  css  js  c++  java
  • CString

    ______CString::Left.

    Return Value:   CString object containing a copy of the specified range of characters. Note that the returnedCString object may be empty.

    // example for CString::Left
    CString s( _T("abcdef") );
    ASSERT( s.Left(2) == _T("ab") );

    //int GetLength( ) const;The count does not include a null terminator.
    int c = s.GetLength();
    //LPTSTR GetBuffer( int nMinBufLength );
    nMinBufLength does not include a null terminator.
    LPTSTR p = s.GetBuffer(c);

    Returns a pointer to the internal character buffer for the CString object. The returned LPTSTR is not const and thus allows direct modification of CString contents.

    If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions.

    The address returned by GetBuffer may not be valid after the call to ReleaseBuffer since additional CStringoperations may cause the CString buffer to be reallocated. The buffer will not be reallocated if you do not change the length of the CString.

    The buffer memory will be freed automatically when the CString object is destroyed.

    Note that if you keep track of the string length yourself, you should not append the terminating null character. You must, however, specify the final string length when you release the buffer with ReleaseBuffer. If you do append a terminating null character, you should pass –1 for the length to ReleaseBuffer and ReleaseBuffer will perform astrlen on the buffer to determine its length.

    Example

    The following example demonstrates the use of CString::GetBuffer.

    // example for CString::GetBuffer
    CString s( "abcd" );
    #ifdef _DEBUG
    afxDump << "CString s " << s << "
    ";
    #endif
    LPTSTR p = s.GetBuffer( 10 );
    strcpy( p, "Hello" );   // directly access CString buffer
    s.ReleaseBuffer( );
    #ifdef _DEBUG
    afxDump << "CString s " << s << "
    ";
    #endif
     
  • 相关阅读:
    初识Vulkan
    网络相关系列之中的一个:Android中使用HttpClient发送HTTP请求
    Hello,Android
    熊猫猪新系统測试之四:Ubuntu 14.04
    iOS OC08,09_内存管理
    XML总结
    【Scala-ML】怎样利用Scala构建并行机器学习系统
    在vs2010中编译log4cxx-0.10.0具体方法(从下载、编译、解决错误具体介绍)
    UI_UITableView_搭建
    Angular 4 子路由
  • 原文地址:https://www.cnblogs.com/aprilapril/p/3224086.html
Copyright © 2011-2022 走看看