cstring

C++字符类型总结区别wchar_t,char,WCHAR

℡╲_俬逩灬. 提交于 2020-02-29 07:48:40
转至:http://www.360doc.com/content/12/0807/01/9290626_228750141.shtml 1.区别wchar_t,char,WCHAR   ANSI:即 char,可用字符串处理函数:strcat( ),strcpy( ), strlen( )等以str打头的函数。   UNICODE:wchar_t是Unicode字符的数据类型,它实际定义在里:   typedef unsigned short wchar_t;   另外,在头文件中有这样的定义:typedef wchar_t WCHAR; 所以WCHAR实际就是wchar_t   wchar_t 可用字符串处理函数:wcscat(),wcscpy(),wcslen()等以wcs打头的函数。为了让编译器识别Unicode字符串,必须以在前面加一个“L”,例如: wchar_t *szTest=L"This is a Unicode string."; 2.TCHAR   在C语言里面提供了 _UNICODE宏(有下划线),在Windows里面提供了UNICODE宏(无下划线),只要定了_UNICODE宏和UNICODE宏,系统就会自 动切换到UNICODE版本,否则,系统按照ANSI的方式进行编译和运行。只定义了宏并不能实现自动的转换,他还需要一系列的字符定义支持。 1. TCHAR

iOS 16进制颜色的宏

时间秒杀一切 提交于 2020-02-26 10:09:24
iOS 16进制颜色的宏 // 参数格式为:0xFFFFFF 16进制 #define kColorWithRGB(rgbValue) \ [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \ green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \ blue :((float)(rgbValue & 0xFF)) / 255.0 alpha:1.0] kColorWithRGB(0xFF0000); 相当于 [UIColor redColor]; // 参数格式为:222,222,222 #define UIColorWithRGB(r, g, b) [UIColor colorWithRed:(r) / 255.f green:(g) / 255.f blue:(b) / 255.f alpha:1.f] 很多地方我们都使用16进制颜色,但iPhone使用的是 UIColor对象,不直接支持16进制颜色,为此,需要我们手动将16进制颜色转换为 UIColor。 - ( UIColor *)getColor:(NSString*)hexColor { unsigned int red,green,blue; NSRange range; range

WinCE平台下BMP转JPG代码备份2

风格不统一 提交于 2020-02-17 14:31:16
1 /********************************************************************************************************* 2 ** Function name: epcCamGetRgbFrame 3 ** Descriptions: 本函数用于获取RGB通道的图像的数据缓存区地址 4 ** input parameters: prAddInfo 存放获取的地址,注意访问该地址的图像数据时候使用SetKMode(TRUE) 5 ** output parameters: 无 6 ** Returned value: TRUE:成功;FALSE:失败 7 *********************************************************************************************************/ 8 9 10 11 12 13 EpcsCam::EpcsCam(void)14 {15 hDLL=LoadLibrary(CString("\\FlashDisk2\\epcCameraLib.dll"));//加载动态链接库MyDll.dll文件;16 17 18 19 }20 21 EpcsCam::~EpcsCam

WinCE平台下BMP转JPG代码备份3

安稳与你 提交于 2020-02-17 14:30:15
1 //带参数的保存位图函数 2 BOOL FileOperate::bmpSaveImage(PTSTR pstrFileName, BITMAPFILEHEADER *pbmfh) 3 { 4 BOOL bSuccess ; 5 DWORD dwBytesWritten ; 6 HANDLE hFile; 7 8 hFile = CreateFile ( pstrFileName, GENERIC_WRITE, 0, NULL, 9 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL) ; 10 11 if (hFile == INVALID_HANDLE_VALUE) { 12 return FALSE ; 13 } 14 15 bSuccess = WriteFile (hFile, pbmfh, pbmfh->bfSize, &dwBytesWritten, NULL); 16 17 CloseHandle (hFile) ; 18 19 if (!bSuccess || (dwBytesWritten != pbmfh->bfSize)) { 20 DeleteFile (pstrFileName) ; 21 return FALSE ; 22 } 23 return TRUE ; 24 } 25 26 //**************

Pros and Cons of different string types in C++

荒凉一梦 提交于 2020-02-04 00:49:10
问题 Sorry to start another of those unanswerable questions on SO, but I'm just curious as to the pros and cons of all the different string types in C++. My particular question is between MFC's CStrings and std::string (since I'm doing Windows only software), but this would extend to any of the string formats in C++. What do you all thing is the best string type to use in C++ and why? UPDATE: I actually found a duplicate question. Thanks to those who already answered. Please direct any new

how to convert CString to Bytes

被刻印的时光 ゝ 提交于 2020-02-02 15:29:00
问题 i am actually tryin to convert a csharp code to c... below is the C# code.. CString data = "world is beautiful"; Byte[] quote = ASCIIEncoding.UTF8.GetBytes(data); in the above code... it converts the string into bytes..similarily is ther a way that i can convert it using C.. Can any body tell what wud be the quivalent code in C? Please help me guys 回答1: Well CString is a C++ class so doing it in C is a little unlikely. But if you wish to get it as a standard multi-byte encoded string then you

VC++2005 CString和char*的相互转换

我是研究僧i 提交于 2020-01-29 05:06:43
首先声明我不是一个高手,而是一个初学者,文章同样也是一个初学者对于CString和char*转换的理解。 因为需要,接触C++一段时间了,其中最为困扰我的问题就是在使用C++的过程中CString和char*的转换,在网上搜索了一下,看到问这个问题的人挺多的。我使用的平台是Win2003+VC 2005,本来这个很简单的问题稍微复杂了一点在2005里面。 在我的工程里面要集成一个用C开发的程序,用VC做windows窗体的界面,在C的函数中有不少是使用char*作为参数的,因此有一个必不可少的步骤就是把CString转换为shar*字符串。 作为一个初学者,遇到这个问题,首先是在baidu上搜索了一下转换的方法,有很多结果,别人也说有效,但是我把它放在我的代码里面的时候,就是出现错误。下面是我的解决办法。 使用CString的GetBuffer方法 CString origCString("Hello,World"); char* CharString = origCString.GetBuffer(origCString.GetLength()+1); 网上的很多文章说的都是这个方法,但是我在VC++2005中编译得到下列信息 Error 1 error C2440: 'initializing' : cannot convert from 'wchar_t *' to

凉脾的比赛

你离开我真会死。 提交于 2020-01-22 19:14:38
文章目录 A - DRM Messages B - Game of Throwns C - Sheba's Amoebas A - DRM Messages 这道题主要是找两个字符串的有种联系 # include <cstdio> # include <iostream> # include <cstring> using namespace std ; int sum , sum_ ; int main ( ) { string s ; cin >> s ; for ( int i = 0 ; i < s . length ( ) / 2 ; i ++ ) sum + = s [ i ] - 'A' ; for ( int i = s . length ( ) / 2 ; i < s . length ( ) ; i ++ ) sum_ + = s [ i ] - 'A' ; for ( int i = 0 ; i < s . length ( ) / 2 ; i ++ ) s [ i ] = ( s [ i ] - 'A' + sum ) % 26 + 'A' ; for ( int i = s . length ( ) / 2 ; i < s . length ( ) ; i ++ ) s [ i ] = ( s [ i ] - 'A' + sum_ ) % 26 + 'A'

C++ CString相关函数

橙三吉。 提交于 2020-01-19 22:58:56
一、CStrig函数 1、Find()   查找字符或字符串,返回字符所在的第一个位置,找不到返回-1 2、Remove()   删除特定的字符 3、TrimLeft()和TrimRight()   TrimLeft()删除左边的对应字符,直至不匹配的字符出现   TrimRight()删除右边的对应字符,直至不匹配的字符出现 4、MakeReverse()   将内容反转 5、Format()   将其他类型的变量转换成CString 6、IsEmpty()   判断CString是否为空 7、GetAt()   取字符串的对应位置的字符 8、GetLength()   取CString字符串的长度 9、GetSize()   取CStringArray字符串数组的大小 10、Split()   将字符串以"-"切割放在字符串数组里面 11、Mid()   取对应位置之后的字符串 12、Left()   取最左边指定位数的字符 13、Right()   取最右边指定位数的字符 14、MakeUp()    转为大写 15、MakeLower()   转为小写 16、Compare()   区分大小写比较字符串,相等为0,大于返回1,小于返回-1 17、CompareNoCase()   不区分大小写比较字符串,相等为0,大于返回1,小于返回-1 18、Delete()  

Why i can't compare CString in MFC

核能气质少年 提交于 2020-01-17 01:23:28
问题 This line. UpdateData(true); if( m_OldPassword.Compare(d.pass) && m_NewPassword.Compare(m_ConfirmPassword) ) m_OldPassword, m_NewPassword, m_ConfirmPassword is variable i added from EditControl m_OldPassword.Compare(d.pass) Result =true (tested) m_NewPassword.Compare(m_ConfirmPassword) Result = false. IMPLEMENT_DYNAMIC(ChangePassword, CDialog) ChangePassword::ChangePassword(CWnd* pParent /*=NULL*/) : CDialog(ChangePassword::IDD, pParent) , m_OldPassword(_T("")) , m_NewPassword(_T("")) , m