[問題] VS2012: 字串中的字元無效。

看板C_and_CPP (C/C++)作者 (皮老闆)時間12年前 (2013/09/25 09:39), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) visual studio 2010,2012 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) none 問題(Question): 原po使用base64演算法,程式碼如下 unsigned char *base64(string inpt,int * len) { int n,i,j,pad; unsigned char *p = NULL; unsigned char *dst = NULL; unsigned char * src = NULL; *len=0; pad=0; n=inpt.length(); src=new unsigned char [n]; for(i=0;i<n;i++) src[i]=inpt[i]; while(n>0&&src[n-1]=='=') { src[n-1]=0; pad++; n--; } for(i=0;i<n;i++) { /* map base64 ASCII character to 6 bit value */ p=(unsigned char *)strchr((const char *)base64,(int)src[i]); if(!p) break; src[i]=p-(unsigned char *)base64; } dst=(unsigned char *)malloc(n*3/4+1); memset(dst,0,n*3/4+1); for(i=0,j=0;i<n;i+=4,j+=3) { dst[j]=(src[i]<<2) + ((src[i+1]&0x30)>>4); dst[j+1]=((src[i+1]&0x0F)<<4) + ((src[i+2]&0x3C)>>2); dst[j+2]=((src[i+2]&0x03)<<6) + src[i+3]; *len+=3; } *len-=pad; return dst; } 該程式碼在vs2010執行正常,但在vs2012則會回傳 <字串中的字元無效。> 哪裡設定錯了嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.33.207.109 ※ 編輯: sohumi 來自: 114.33.207.109 (09/25 21:02)

09/30 01:56, , 1F
專案設定中的unicode,multibyte更改一下看看
09/30 01:56, 1F
文章代碼(AID): #1IGZxeVe (C_and_CPP)
文章代碼(AID): #1IGZxeVe (C_and_CPP)