cstring

Help with \0 terminated strings in C#

℡╲_俬逩灬. 提交于 2020-01-10 21:49:27
问题 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? 回答1: .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

Help with \0 terminated strings in C#

被刻印的时光 ゝ 提交于 2020-01-10 21:48:47
问题 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? 回答1: .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

HDU1267(递推)

偶尔善良 提交于 2020-01-10 09:28:58
问题描述:假定一个字符串由m个H和n个D组成,从左到右扫描该串,如果字符H的累计数总是不小于字符D的累计数,那么,满足条件的字符串总数。 思路:递推+long long 处理 a[i][0]:表示HHH....此时的情况为1,则a[i][0]=1; a[0][i]:表示...DDD,此时的情况为0,则a[0][i]=0; a[i][j]=a[i-1][j]+a[i][j-1],此时表示一般情况下相加,其中j<=i; 代码如下: Sample Input 1 1 3 1 Sample Output 1 3 #include<iostream> #include<cstring> using namespace std; int main(){ long long int a[25][25]; int i,j,m,n; memset(a,0,sizeof(a)); for(i=1;i<=20;i++) a[i][0]=1; for(i=1;i<=20;i++) for(j=1;j<=i;j++) a[i][j]=a[i-1][j]+a[i][j-1];//跑楼梯 while(scanf("%d %d",&m,&n)!=EOF) printf("%lld\n",a[m][n]); } /*Sample Input 1 1 3 1 Sample Output 1 3*/ 来源: CSDN

MFC树形控件加载Access数据库数据

不打扰是莪最后的温柔 提交于 2020-01-09 01:41:14
研究了好几天,今天终于弄好了,下面是代码 [dlg.cpp] 在初始函数OnInitDialog()中加 HICON hIcon[3]; HTREEITEM hRoot; //加载三个图标 hIcon[0] = theApp.LoadIconW(IDI_ICON1); hIcon[1] = theApp.LoadIconW(IDI_ICON3); hIcon[2] = theApp.LoadIconW(IDI_ICON2); m_imageList.Create(16, 16, ILC_COLOR16, 3, 3); for (int i=0;i<3;i++) { m_imageList.Add(hIcon[i]); } //绑定树控件与ImaageList m_webTree.SetImageList(&m_imageList, TVSIL_NORMAL); //初始化Ado环境 AfxOleInit(); hRoot = NULL; OpenConn(); //打开数据函数 LoadTreeCtrlData(hRoot,_T("0")); //递归加数据到树控件中 CloseConn(); //关闭数据库 //下面就是递归函数 void CMFCApp_CTreeCtrl_testDlg::LoadTreeCtrlData(HTREEITEM hItem,CString mid

VS 错误处理

喜欢而已 提交于 2020-01-07 12:12:43
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1错误: fatal error C1010: unexpected endof file while looking for precompiled header. Did you forget to add '#include"StdAfx.h"' to your source? #include"StdAfx.h" 你把这个放在头文件里面就行了 2 vc++ 编程出现错误error C2447: missing function header (old-styleformal list?) 原因:函数后面多了分号; SUNSHINE_APISSN_RETURN SsnWriteProfileString(__in INT nPlugInId, __in_opt LPTSTRlpszGroupName, __in LPTSTR lpszKey, __in LPTSTR lpszValue) ; 3 errorC2491: 'SsnWriteProfileString' : definition of dllimport function not allowed 错误 C2491:“SsnWriteProfileString’:dllimport 函数的定义不允许的 SUNSHINE_API SSN

a swift questions about String and c strcpy

我的梦境 提交于 2020-01-05 09:27:47
问题 I want to call a c++ function in swift bool getId3Info(const char * filename , char *artist , char * title ) { // get the file's id3v2 tag, write info back strcpy(artist,(const char*) id3v2tag->artist().toCString(true)); strcpy(title,id3v2tag->title().toCString(true)); } So I write a object-c wrapper for this function: -(bool) getId3Info:(const char * )filename :( const char *)artist :( const char *) title { return getId3Info(filename, (char*)artist, (char*)title); } So the questions is I can

Write a unicode CString to a file using WriteFile API

[亡魂溺海] 提交于 2020-01-01 19:34:49
问题 How can I write contents of a CString instance to a file opened by CreateFile using WriteFile Win32 API function? Please note MFC is not used, and CString is used by including "atlstr.h" edit: Can just I do WriteFile(handle, cstr, cstr.GetLength(), &dwWritten, NULL); or WriteFile(handle, cstr, cstr.GetLength() * sizeof(TCHAR), &dwWritten, NULL); ? 回答1: With ATL it's like this: CString sValue; CStringW sValueW(sValue); // NOTE: CT2CW() can be used instead CAtlFile File; ATLENSURE_SUCCEEDED

MFC获取时间字符串

爷,独闯天下 提交于 2020-01-01 13:04:29
基本上有2种方式,一种是利用"time.h"文件中的系统函数;另一种是利用CTime类。 利用系统函数。 # include "time.h" CString time_cstr ; SYSTEMTIME st ; //定义系统时间结构体的对象 GetLocalTime ( & st ) ; //调用GetLocalTime获得当前时间,并保存在结构体st中 time_cstr . Format ( _T ( "%04d-%02d-%02d %02d:%02d:%02d:%3d" ) , st . wYear , st . wMonth , st . wDay , st . wHour , st . wMinute , st . wSecond , st . wMilliseconds ) ; 利用CTime类。 CString MyGetCurrenTime ( ) { CTime time = CTime : : GetCurrentTime ( ) ; CString curTime ; curTime . Format ( L "%04d-%02d-%02d %02d:%02d:%02d" , time . GetYear ( ) , time . GetMonth ( ) , time . GetDay ( ) , time . GetHour ( ) , time .

Simple modification of C strings using pointers

♀尐吖头ヾ 提交于 2019-12-31 01:45:08
问题 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

CString、std::string格式化字符串

冷暖自知 提交于 2019-12-30 19:55:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> =============================CString================================== 当有多个字串时,比如 int n1 = 5; int n2 = 10; char sz1[] = "abcdefg"; char sz2[] = "hijklmn"; 用std中的string如何写出最简单的代码得到MFC中CString如下效果: CString s; s.Format(" result: %d + %d = %d/n sz1: %s/n sz2: %s/n", n1, n2, n1+n2, sz1, sz2 ); ===========================std::string================================== int n1 = 5; int n2 = 10; char sz1[] = "abcdefg"; char sz2[] = "hijklmn"; std::ostringstream ostr; // include <sstream> ostr << "result:" << n1 << "+" << n2 << "=" << n1+n2 << "/nsz1:" << sz1 << "/nsz2: