cstring

Cannot modify C string

瘦欲@ 提交于 2019-11-28 09:22:40
Consider the following code. int main(void) { char * test = "abcdefghijklmnopqrstuvwxyz"; test[5] = 'x'; printf("%s\n", test); return EXIT_SUCCESS; } In my opinion, this should print abcdexghij. However, it just terminates without printing anything. int main(void) { char * test = "abcdefghijklmnopqrstuvwxyz"; printf("%s\n", test); return EXIT_SUCCESS; } This however, works just fine, so did I misunderstand the concept of manipulating C strings or something? In case it is important, I'm running Mac OS X 10.6 and it is a 32-bit binary I'm compiling. This answer is good, but not quite complete.

Objective-C - Converting NSString to a C string [duplicate]

烂漫一生 提交于 2019-11-28 06:30:56
问题 This question already has an answer here : Closed 8 years ago . Possible Duplicate: objc warning: “discard qualifiers from pointer target type” I'm having a bit of trouble converting an NSString to a C string. const char *input_image = [[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String]; const char *output_image = [[[NSBundle mainBundle] pathForResource:@"iphone_resized" ofType:@"png"] UTF8String]; const char *argv[] = { "convert", input_image, "-resize", "100x100",

MFC/WTL字符串转换(CString - char)

ε祈祈猫儿з 提交于 2019-11-28 05:47:40
CString: 当VS编码环境为Unicode时,CString就是CStringW。当VS编码环境为多字节时,CString就是CStringA。 在C/C++中同样存在着两种环境的字符串:char 和 wchar_t。 本文的目的是:转换他们。 Code Start : class UStrToAscChar //CStringW + wchar_t* -> char* { public: UStrToAscChar(const CStringW cs) { int n = WideCharToMultiByte(CP_ACP,0,cs,-1,NULL,0,NULL,NULL); if(n <= 0) buff = NULL; buff = new char[n]; memset(buff,0,n); WideCharToMultiByte(CP_ACP,0,cs,-1,buff,n,NULL,NULL); } ~UStrToAscChar() { delete buff; } const char* operator &() //注意这是成员函数重载了运算符,友元函数重载需要参数 { return buff; } private: char* buff; }; class UStrToWChar //CStringW ->wchar_t* { public:

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

倖福魔咒の 提交于 2019-11-28 04:35:08
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. CFile CSVFile( m

纪中21日T3 2118. 【2016-12-30普及组模拟】最大公约数

痞子三分冷 提交于 2019-11-28 03:35:43
纪中21日T3 2118. 最大公约数 (File IO): input:gcd.in output:gcd.out 时间限制: 1000 ms 空间限制: 262144 KB 具体限制 Goto ProblemSet 题目描述 给出两个正整数A,B,求它们的最大公约数。 输入 第一行一个正整数A。 第二行一个正整数B。 输出 在第一行输出一个整数,表示A,B的最大公约数。 样例输入 1824 样例输出 6 数据范围限制 在40%的数据中,1 ≤ A,B ≤ 10^6 在60%的数据中,1 ≤ A,B ≤ 10^18 在80%的数据中,1 ≤ A,B ≤ 10^100 在100%的数据中,1 ≤ A,B ≤ 10^1000 Solution Algorithm1 正常的gcd(a,b)=gcd(b,a%b); 开unsigned long long可得六十分(应该不会超时) Code1 #pragma GCC optimize(2) #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include<set> #include<queue> #include<vector> #define IL inline using

CListCtrl 使用技巧

淺唱寂寞╮ 提交于 2019-11-28 03:09:14
以下未经说明,listctrl默认view 风格为report 相关类及处理函数 MFC:CListCtrl类 SDK:以 “ListView_”开头的一些宏。如 ListView_InsertColumn 1. CListCtrl 风格 LVS_ICON: 为每个item显示大图标 LVS_SMALLICON: 为每个item显示小图标 LVS_LIST: 显示一列带有小图标的item LVS_REPORT: 显示item详细资料 直观的理解:windows资源管理器,“查看”标签下的“大图标,小图标,列表,详细资料” 2. 设置listctrl 风格及扩展风格 LONG lStyle; lStyle = GetWindowLong(m_list.m_hWnd, GWL_STYLE);//获取当前窗口style lStyle &= ~LVS_TYPEMASK; //清除显示方式位 lStyle |= LVS_REPORT; //设置style SetWindowLong(m_list.m_hWnd, GWL_STYLE, lStyle);//设置style DWORD dwStyle = m_list.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)

VC使用ADO

╄→尐↘猪︶ㄣ 提交于 2019-11-28 03:09:05
一、ADO概述   ADO是Microsoft为最新和最强大的数据访问范例 OLE DB 而设计的,是一个便于使用的应用程序层接口。ADO 使您能够编写应用程序以通过 OLE. DB 提供者访问和操作数据库服务器中的数据。ADO 最主要的优点是易于使用、速度快、内存支出少和磁盘遗迹小。ADO 在关键的应用方案中使用最少的网络流量,并且在前端和数据源之间使用最少的层数,所有这些都是为了提供轻量、高性能的接口。之所以称为 ADO,是用了一个比较熟悉的暗喻,OLE 自动化接口。   OLE DB是一组”组件对象模型”(COM) 接口,是新的数据库低层接口,它封装了ODBC的功能,并以统一的方式访问存储在不同信息源中的数据。OLE DB是Microsoft UDA(Universal Data Access)策略的技术基础。OLE DB 为任何数据源提供了高性能的访问,这些数据源包括关系和非关系数据库、电子邮件和文件系统、文本和图形、自定义业务对象等等。也就是说,OLE DB 并不局限于 ISAM、Jet 甚至关系数据源,它能够处理任何类型的数据,而不考虑它们的格式和存储方法。在实际应用中,这种多样性意味着可以访问驻留在 Excel 电子数据表、文本文件、电子邮件/目录服务甚至邮件服务器,诸如 Microsoft Exchange 中的数据。但是,OLE DB

What does _T stands for in a CString

梦想与她 提交于 2019-11-27 22:42:40
What does the "T" represents in a string. For example _T("Hello").I have seen this in projects where unicode support is needed.What it actually tells the processor _T stands for “text”. It will turn your literal into a Unicode wide character literal if and only if you are compiling your sources with Unicode support. See http://msdn.microsoft.com/en-us/library/c426s321.aspx . From MSDN: Use the _T macro to code literal strings generically, so they compile as Unicode strings under Unicode or as ANSI strings (including MBCS) without Unicode john It's actually used for projects where Unicode and

Simply encrypt a string in C

为君一笑 提交于 2019-11-27 16:41:59
问题 I'm trying to encrypt a query string on a game I'm making when opening a url. It doesn't have to be complicated, in fact since I'm working from a game engine it needs to be as simple as possible. It tends to fuss if I get too low level. I've already created the query string, I just need to take each char of it and subtract 15 from the char to lightly encrypt it. I'm just wanting to make a simple encryption that will deter most users. I wish I could give a code example but I'm not too

Working with C strings in Swift, or: How to convert UnsafePointer<CChar> to CString

Deadly 提交于 2019-11-27 15:40:06
问题 While playing with Standard C Library functions in Swift, I came across problems when passing C strings around. As a simple example (just to demonstrate the problem), the Standard C Library function char * strdup(const char *s1); is exposed to Swift as func strdup(_: CString) -> UnsafePointer<CChar> which means that the return value of strdup() cannot be passed to another strdup() call: let s1 : CString = "abc" let s2 = strdup(s1) // OK, s2 is a UnsafePointer<CChar> let s3 = strdup(s2) //