cstring

Simple modification of C strings using pointers

隐身守侯 提交于 2019-12-01 20:22:50
I have two pointers to the same C string. If I increment the second pointer by one, and assign the value of the second pointer to that of the first, I expect the first character of the first string to be changed. For example: #include "stdio.h" int main() { char* original_str = "ABC"; // Get pointer to "ABC" char* off_by_one = original_str; // Duplicate pointer to "ABC" off_by_one++; // Increment duplicate by one: now "BC" *original_str = *off_by_one; // Set 1st char of one to 1st char of other printf("%s\n", original_str); // Prints "ABC" (why not "BBC"?) *original_str = *(off_by_one + 1); //

封装ADO库之MFC应用

人盡茶涼 提交于 2019-12-01 19:12:30
  Microsoft Activex Data Objects(ADO)支持用于建立基于客户端/服务器和web的应用程序开发的主要功能。其主要优点是易于使用、高速度、低内存支出和占用磁盘空间较少。   本次封装的CadoInterface类仅针对MFC的使用,目的是优化对ADO的操作,避免频繁写try catch(...)以及在连库、开表、写数据、读数据等过程中一些重复性的工作。该类仅对一些常用的操作进行封装,用户可以根据需要进行修改和扩展。   封装类主要包括:基本操作、增值操作、支持算法与支持结构。基本操作、增值操作、支持算法在AdoInterface.h与AdoInterface.cpp中声明定义,支持结构在DataBelong.h中定义。 一、封装类的关系   图一 封装类关系图,箭头代表包含关系,用户使用时只需包含界面文件AdoInterface.h 二、基本操作部分 (一)连接数据库   CString Conn="provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb";   myado.ConnecDataLibrary(Conn,"","");   本例连接了一个无密码的Access库,如用其他方式连接数据库,用户可自行更改连接字符串,或者以枚举的方式将多种连接方式封装到本函数中。 (二)开表   myado

How do I convert an ATL/MFC CString to a QString?

独自空忆成欢 提交于 2019-12-01 18:00:30
Given the encoding of the project is probably Unicode (but not for sure) what is the best way of converting ATL::CString to QString? What I have thought of is this: CString c(_T("SOME_TEXT")); //... std::basic_string<TCHAR> intermediate((LPCTSTR)c); QString q; #ifdef _UNICODE q = QString::fromStdWString(intermediate); #else q = QString::fromStdString(intermediate); #endif Do you think that it works? Any other ideas? You don't need the intermediate conversion to a std::string . The CString class can be treated as a simple C-style string; that is, an array of characters. All you have to do is

Which is better code for converting BSTR parameters to ANSI in C/C++?

会有一股神秘感。 提交于 2019-12-01 08:57:54
So far I've discovered I can convert incoming BSTRs to ANSI in two (of many?) ways, and I'm curious to know whether one is "better" than the other with respect to speed / efficiency etc. The way I've been using for a while is use the USES_CONVERSION and W2A macros, e.g. BSTR __stdcall F(BSTR p1, BSTR p2 ) { USES_CONVERSION; LPSTR sNum1 = W2A( p1 ); LPSTR sNum2 = W2A( p2 ); Recently, however, I came across another technique: BSTR __stdcall F(BSTR p1, BSTR p2 ) { long amt = wcstombs( NULL, p1, 1 ); sNum1 = (char *) malloc( amt ); wcstombs( sNum1, p1, amt ); *(sNum1 + amt) = '\0'; amt = wcstombs(

概率与期望,成为预言家的第一步

╄→尐↘猪︶ㄣ 提交于 2019-11-30 17:56:50
目录 参考文献 概率初解 期望 期望的定义与性质 期望定义 期望性质 证明性质 性质1 性质2 题目练习 例题 简单期望 概率DP 条件期望 题目 期望初练 二次期望 简单期望题 转化题目意思 三次期望 条件期望 当期望到了图上 图上进阶 毒瘤题在树上 二次期望题 小结 参考文献 此垃圾博客参考于一下大佬文献: 你谷日报吼: https://45475.blog.luogu.org/mathematical-expectation 每道题的题解。 百度百科 貌似就这些了QMQ 概率初解 概率初解 概率其实很迷。 比如你扔一个六面骰子,然后扔到 \(3\) 的概率是 \(\frac{1}{6}\) 。 度娘的话: 概率,亦称“或然率”,它是反映随机事件出现的可能性(likelihood)大小。 随机事件是指在相同条件下,可能出现也可能不出现的事件。 例如,从一批有正品和次品的商品中,随意抽取一件,“抽得的是正品”就是一个随机事件。 设对某一随机现象进行了n次试验与观察,其中A事件出现了m次,即其出现的频率为m/n。 经过大量反复试验,常有m/n越来越接近于某个确定的常数(此论断证明详见伯努利大数定律)。 该常数即为事件A出现的概率,常用P (A) 表示。 概率抽象理解就行了。 初中还不知道概率别学OI了。 期望 期望的定义与性质 以下摘自日报 博主偷懒也不至于这么懒吧

Help with \\0 terminated strings in C#

…衆ロ難τιáo~ 提交于 2019-11-30 17:25:53
I'm using a low level native API where I send an unsafe byte buffer pointer to get a c-string value. So it gives me // using byte[255] c_str string s = new string(Encoding.ASCII.GetChars(c_str)); // now s == "heresastring\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0(etc)"; So obviously I'm not doing it right, how I get rid of the excess? .NET strings are not null-terminated (as you may have guessed from this). So, you can treat the '\0' as you would treat any normal character. Normal string manipulation will fix things for you. Here are some (but not all) options. s = s.Trim('\0'); s = s.Replace("\0", "");

Why is my char* writable and sometimes read only in C++

▼魔方 西西 提交于 2019-11-30 09:23:42
问题 I have had really big problems understand the char* lately. Let's say I made a recursive function to revert a char* but depending on how I initialize it I get some access violations, and in my C++ primer I didn't find anything giving me the right path to understand so I am seeking your help. CASE 1 First case where I got access violation when trying to swap letters around: char * bob = "hello"; CASE 2 Then I tried this to get it work char * bob = new char[5]; bob[0] = 'h'; bob[1] = 'e'; bob[2

How should I allocate memory for c-string char array?

孤人 提交于 2019-11-30 05:47:31
问题 So in attempting to learn how to use C-Strings in C++, I'm running into issues with memory allocation. The idea here is that a new string is created of the format (s1 + sep + s2) The text I'm using provided the header, so I can't change that, but I'm running into issues trying to set the size of char str[]. I am getting an error saying that sLength is not constant, and therefore cannot be used to set the size of an array. I'm relatively new to C++ so this is a two part question. Is this

How can I hash a string to an int using c++?

我与影子孤独终老i 提交于 2019-11-30 05:04:48
I have to write my own hash function. If I wanted to just make the simple hash function that maps each letter in the string to a numerical value (i.e. a=1, b=2, c=3, ...), is there a way I can perform this hash on a string without having to first convert it to a c-string to look at each individual char? Is there a more efficient way of hashing strings? Alex Martelli Re the first question, sure, e.g, something like: int hash = 0; int offset = 'a' - 1; for(string::const_iterator it=s.begin(); it!=s.end(); ++it) { hash = hash << 1 | (*it - offset); } regarding the second, there are many better

ios常用宏定义

大兔子大兔子 提交于 2019-11-29 15:56:13
//十六进制转rgb #define ColorWithHexString(hexString) [UIColor colorWithHexString:hexString] // 获取RGB颜色 #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a] #define RGB(r,g,b) RGBA(r,g,b,1.0f) //字体颜色 #define TITLE_EA_COLOR RGB(51,51,51) #define TITLE_CD_COLOR RGB(34, 34, 34) #define TITLE_AEC_COLOR RGB(153,153,153) #define VIEW_BDA_COLOR RGB(241,241,241) #define SELECT_LINE_Color RGB(216,0,8) #define SELECT_TITLE_Color RGB(58,58,58) #define Button_COLOR1 RGB(51,51,51) #define LINE_COLOR RGB(168,168,168) //颜色 #define ColorHex_333333 ColorWithHexString(@"#333333"