cstring

C++: how to convert ASCII or ANSI to UTF8 and stores in std::string

怎甘沉沦 提交于 2019-12-03 03:59:50
My company use some code like this: std::string(CT2CA(some_CString)).c_str() which I believe it converts a Unicode string (whose type is CString)into ANSI encoding, and this string is for a email's subject. However, header of the email (which includes the subject) indicates that the mail client should decode it as a unicode (this is how the original code does). Thus, some German chars like "ä ö ü" will not be properly displayed as the title. Is there anyway that I can put this header back to UTF8 and store into a std::string or const char*? I know there are a lot of smarter ways to do this,

assignment makes pointer from integer without cast [enabled by default]

匿名 (未验证) 提交于 2019-12-03 02:41:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have googled this and see many answers, but none fits my situation. This is my main(): char * cString; puts("Please enter data you want to encrypt."); cString = getInput(cString, &iStringSize); printf("The message is: %s\n\n", cString); char * strEncrypt; strEncrypt = encrypt(cString, offset); printf("The encrypted message is: %s\n\n", strEncrypt); return 0; This program basically reads in an arbitrary input, then encrypt it. This is the getInput function: char * getInput(char *cString, int * iStringSize) { puts("Begin reading input.");

vc++ - How to convert a CString into LPCWSTR

匿名 (未验证) 提交于 2019-12-03 02:27:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I tried to do this , but I didn't find any method for this. I am asking this due to the fact that I am new to windows. I tried stl-strings, but visual studio 2008- accumulates bugs in stl-wstring-handling. I will say a lot about that thing later, in other question. Now Can anybody shed light on this issue? 回答1: Use the conversion class CT2CW like this FuncTakingLPCWSTR(CT2CW(cstring_var)) . This is guaranteed to work in either Unicode or MBCS builds. Also, keep in mind that the string passed to the function may be a temporary, so don't store

C++ MFC double to CString

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Sorry for my English. I need to convert double value to CString, because i need to do AfxMessageBox(double_value); I find this: std::ostringstream ost; ost << double_value; std::cout << "As string: " << ost.str() << std::endl; //AfxMessageBox(ost.str()); - Does not work. How i can do this? 回答1: AfxMessageBox expects a CString object, so format the double into a CString and pass that: CString str; str.Format("As string: %g", double); AfxMessageBox(str); Edit: If you want the value displayed as an integer (no value after decimal point) then

using MFC CMap for CString int pairs

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm currently working on a DLL that needs to convert back and forth between the friendly name for a value and the value itself. As this code is used in many places throughout the codebase, I want to try and keep it simple and in a single function or object so I only have to declare them once. From my reading it looks like CMap is the tool for the job, but I can't seem to discover any combination of template arguments that compiles without errors. My values are CString and int . I tried the following definition: CMap<int, int, CString,

UTF-8, CString and CFile? (C++, MFC)

匿名 (未验证) 提交于 2019-12-03 01:14:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm currently working on a MFC program that specifically has to work with UTF-8. At some point, I have to write UTF-8 data into a file; to do that, I'm using CFiles and CStrings. When I get to write utf-8 (russian characters, to be more precise) data into a file, the output looks like and etc. This is assurely not utf-8. To read this data properly, I have to change my system settings; changing non ASCII characters to a russian encoding table does work, but then all my latin based non-ascii characters get to fail. Anyway, that's how I do it.

MFC中CString.Format的详细用法

匿名 (未验证) 提交于 2019-12-03 00:32:02
转载: https://blog.csdn.net/wangkaishou/article/details/5846152 在MFC程序中,使用CString来处理字符串是一个很不错的选择。CString既可以处理Unicode标准的字符串,也可以处理ANSI标准的字符串。CString的Format方法给我们进行字符串的转换带来了很大的方便,比如常见的int、float和double这些数字类型转换为CString字符串只需一行代码就可以实现。   先看看Format用于转换的格式字符:   1、int转换为CString:   CString str;   int number=15;   //str="15"   str.Format(_T("%d"),number);   //str=" 15"(前面有两个空格;4表示将占用4位,如果数字超过4位将输出所有数字,不会截断)   str.Format(_T("%4d"),number);   //str="0015"(.4表示将占用4位,如果数字超过4位将输出所有数字,不会截断)   str.Format(_T("%.4d"),number);   long转换为CString的方法与上面相似,只需要把%d改为%ld就可以了。   2、double转换为CString:   CString str;   double num

MFC SendMessage()函数传递字符串

匿名 (未验证) 提交于 2019-12-02 23:35:02
CString cstr1 = _T("123"); CString cstr2 = _T("hello"); ::SendMessage(hWnd, WM_XXX, (WPARAM)(LPCTSTR)cstr1, (LPARAM)(LPCTSTR)cstr2); LRESULT CXXXDlg::OnXXX(WPARAM wParam, LPARAM lParam) { CString cstr1 = (LPCTSTR)wParam; CString cstr2 = (LPCTSTR)lParam; } // 加入映射宏 BEGIN_MESSAGE_MAP(CXXXDlg, CDialogEx) ... ON_MESSAGE(WM_XXX, OnXXX) ... END_MESSAGE_MAP() // 头文件添加 #define WM_XXX (WM_USER+1001) afx_msg LRESULT OnXXX(WPARAM wParam, LPARAM lParam); 文章来源: https://blog.csdn.net/u011555996/article/details/90550593

How do I pass this array of c strings correctly? [closed]

若如初见. 提交于 2019-12-02 23:20:59
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have my array of C-Strings declared as: char *argv[MAXARGS]; MAXARGS basically just tells us how many c strings are in the array for indexing purposes. I want to pass it to this function below... int builtin_cmd(char **argv) but nothing seems to go through, I called the function like this. char *argv[MAXARGS];

Remove character from array where spaces and punctuation marks are found [duplicate]

旧巷老猫 提交于 2019-12-02 22:52:39
问题 This question already has answers here : C++ Remove punctuation from String (12 answers) Closed 5 years ago . In my program, I am checking whole cstring, if any spaces or punctuation marks are found, just add empty character to that location but the complilor is giving me an error: empty character constant. Please help me out, in my loop i am checking like this if(ispunct(str1[start])) { str1[start]=''; // << empty character constant. } if(isspace(str1[start])) { str1[start]=''; // << empty