标签:cstring c++ 存储 strlen sizeof
- sizeof(cs)/sizeof(char)
- sizeof(ws)/sizeof(wchar_t)
- size_t strlen( const char *string );
- size_t wcslen( const wchar_t *string );
- int GetLength( ) const throw( );
- size_type length( ) const;
- size_type size( ) const;
- unsigned int length ( ) const throw( );
- 01 #include "stdafx.h"
- 02 #include "string"
- 03 #include "comutil.h"
- 04 #pragma comment( lib, "comsuppw.lib" )
- 05
- 06 using namespace std;
- 07
- 08 int main()
- 09 {
- 10 char s1[] = "中文ABC";
- 11 wchar_t s2[] = L"中文ABC";
- 12
- 13 //使用sizeof获取字符串长度
- 14 printf("sizeof s1: %d\r\n", sizeof(s1));
- 15 printf("sizeof s2: %d\r\n", sizeof(s2));
- 16
- 17 //使用strlen获取字符串长度
- 18 printf("strlen(s1): %d\r\n", strlen(s1));
- 19 printf("wcslen(s2): %d\r\n", wcslen(s2));
- 20
- 21 //使用CString::GetLength()获取字符串长度
- 22 CStringA sa = s1;
- 23 CStringW sw = s2;
- 24
- 25 printf("sa.GetLength(): %d\r\n", sa.GetLength());
- 26 printf("sw.GetLength(): %d\r\n", sw.GetLength());
- 27
- 28 //使用string::size()获取字符串长度
- 29 string ss1 = s1;
- 30 wstring ss2 = s2;
- 31
- 32 printf("ss1.size(): %d\r\n", ss1.size());
- 33 printf("ss2.size(): %d\r\n", ss2.size());
- 34
- 35 //使用_bstr_t::length()获取字符串长度
- 36 _bstr_t bs1(s1);
- 37 _bstr_t bs2(s2);
- 38
- 39 printf("bs1.length(): %d\r\n", bs1.length());
- 40 printf("bs2.length(): %d\r\n", bs2.length());
- 41
- 42 return 0;
- 43 }
标签:cstring c++ 存储 strlen sizeof
原文地址:http://blog.csdn.net/a576699534/article/details/42610901