CString 与 const char* 的拼接

本文详细介绍了在使用不同版本的Visual Studio编译SSL证书路径时遇到的问题,以及如何通过修改项目属性解决由字符集不匹配导致的错误。包括将‘使用Unicode字符集’更改为‘使用多字节字符集’的操作步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

extern "C" __declspec(dllexportvoid _stdcall setSSLCertificateFilePath(const char* caCrtFile, const char* serverCrtFile, const char* serverKeyFile);

以上函数,用VS2008 编译时,没有问题


setSSLCertificateFilePath(theApp.GetAppPath()+"\\ca.crt", theApp.GetAppPath()+"\\server.crt", theApp.GetAppPath()+"\\server.key");


theApp.GetAppPath() 为CString&


后改用VS2005编译时,就报错


错误9error C2679: 二进制“+”: 没有找到接受“const char [8]”类型的右操作数的运算符(或没有可接受的转换)d:\source\eventlibsource\win32\appfl\testpro\testprodlg.cpp164


原因是VS2005默认使用的是Unicode字符集


修改VS2005项目属性:常规->字符集


将“使用Unicode字符集”改为“使用多字节字符集”即可。

#include <cstdlib> #include <iostream> using namespace std; int strlen(const char * s) { int i = 0; for(; s[i]; ++i); return i; } void strcpy(char * d,const char * s) { int i = 0; for( i = 0; s[i]; ++i) d[i] = s[i]; d[i] = 0; } int strcmp(const char * s1,const char * s2) { for(int i = 0; s1[i] && s2[i] ; ++i) { if( s1[i] < s2[i] ) return -1; else if( s1[i] > s2[i]) return 1; } return 0; } void strcat(char * d,const char * s) { int len = strlen(d); strcpy(d+len,s); } class MyString { private: char *s; public: MyString(){ } MyString(const char* other){ strcpy(s,other); } MyString(const MyString& other){ strcpy(s,other.s); } ~MyString(){ delete []s; } MyString& operator=(const char* other){ strcpy(s,other); return *this; } MyString& operator=(const MyString& other){ if(this!=&other){ delete []s; s=new char[strlen(other.s)+1]; strcpy(s,other.s); } return *this; } MyString operator+(const MyString& other){ MyString result; result.s=new char[strlen(s)+strlen(other.s)+1]; strcpy(result.s,s); strcat(result.s,other.s); return result; } MyString& operator+=(const char* other){ char*temp=new char [strlen(s)+strlen(other)+1]; strcpy(temp,s); strcat(temp,other); delete[] s; s=temp; return *this; } MyString operator+(const char* other){ MyString result; result.s=new char[strlen(s)+strlen(other)+1]; strcpy(result.s,s); strcat(result.s,other); return result; } friend ostream& operator<<(ostream& os,const MyString& t){ os<<t.s; return os; } char& operator[](int index){ return s[index]; } char* operator()(int x,int y){ int i; char* temp; temp=new char [y-x+1]; for(i=0;i<y-x;i++){ temp[i]=s[x+i]; } temp[i]='0'; return temp; } friend MyString operator+(const char* other,const MyString& other2){ MyString result; result.s=new char[strlen(other)+strlen(other2.s)+1]; strcpy(result.s,other); strcat(result.s,other2.s); return result; } bool operator
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值