错误C2664 无法将参数1从CString转换为const char*

october1993 2016-03-22 02:55:39

用的VS2015和opencv3.0
想用MFC工程做一个点击按钮,选择一张图片把图片显示出来,可是出现错误如图,求大神们指点
...全文
1074 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
puddingli 2016-03-22
  • 打赏
  • 举报
回复 1
改成多字节字符集就好了,或者要用Unicode字符集的话,就把代码改成cvLoadImage(CT2CA(strNamaFile),
shenyi0106 2016-03-22
  • 打赏
  • 举报
回复
右键点击项目,选择“属性”

在”配置属性“页,选择”常规“,找到”字符集“,改成”未设置“,保存


重新编译
随笔 - 764 文章 - 3 评论 - 196 CString,string,char*之间的转换(转) 这三种类型各有各的优点,比如CString比较灵活,是基于MFC常用的类型,安全性也最高,但可移植性最差。string是使用STL时必不可少的类型,所以是做工程时必须熟练掌握的;char*是从学习C语言开始就已经和我们形影不离的了,有许多API都是以char*作为参数输入的。所以熟练掌握三者之间的转换十分必要。 以下我用简单的图示指出三者之间的关系,并以标号对应转换的方法。 1 string to CString CString.format("%s",string.c_str()); 2 CString to string string str(CString.GetBuffer(str.GetLength())); 3 string to char * char *p=string.c_str(); 4 char * to string string str(char*); 5 CString to char * strcpy(char,CString,sizeof(char)); 6 char * to CString CString.format("%s",char*); CString的format方法是非常好用的。string的c_str()也是非常常用的,但要注意和char *转换时,要把char定义成为const char*,这样是最安全的。 以上函数UNICODE编码也没问题:unicode下照用,加个_T()宏就行了,像这样子_T("%s") 补充: CString 可能是 CStringW/CStringA,在与 string 转换时,如果是 CStringW,还涉及编码转换问题。下面以 CStringA 来说明。 1 string to CString CString.format("%s",string.c_str()); CStringA = string.c_str() 就可以了 2 CString to string string str(CString.GetBuffer(str.GetLength())); GetBuffer 有参数的话,可能导致内部的分配空间动作,要进行后续 ReleaseBuffer 操作。 string = CStringA string = CStringA.GetBuffer(); 3 string to char * char *p=string.c_str(); 4 char * to string string str(char*); 5 CString to char * strcpy(char *,CString,sizeof(char)); 按照 3 风格,这里应该 char * = CStringA; 或者 char *p = CStringA.GetBuffer(); 6 char * to CString CStringA = char * 就可以了
rsa算法设计程序 #if !defined(AFX_RSAA_H__081D9EE0_1245_11D5_80AC_0000E8810675__INCLUDED_) #define AFX_RSAA_H__081D9EE0_1245_11D5_80AC_0000E8810675__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // RsaA.h : header file // #include #include #include<string.h> #include const DATALENGTH=350; //大数类型的长度 const MLENGTH=10; //质数的长度 const TESTNUM=30; //测试质数时的比较的次数 const SKLENGTH=4; //私钥的长度 typedef signed char byteint[DATALENGTH]; //定义大数类型 typedef signed char mtype[MLENGTH]; //定义质数的大数类型 //extern "C" __declspec(dllexport) void RsaAGenKeys(CString& pk,CString& sk,CString& R); //提供给服务器使用的秘钥产生函数 //extern "C" __declspec(dllexport) int RsaAEncrypt(CString& source,const char* key,const char* R,CStringArray& result);//加密 //extern "C" __declspec(dllexport) CString RsaADecrypt(CStringArray& source,const char* sk,const char* R);//解密 ///////////////////////////////////////////////////////////////////////////// // CRsaA command target //实现RSA算法的类 class CRsaA : public CCmdTarget { DECLARE_DYNCREATE(CRsaA) CRsaA(); // protected constructor used by dynamic creation // 成员函数 private: void InitInt(void); //基本数据常量的初始化 int IntValid(byteint validtemp); //返回大数validtemp的非零位的个数 int IntCmp(byteint A,byteint B); //比较大数A和B是否相等 //自定义类型的基本运算 void Plus(byteint A,byteint B,byteint C); //C=A+B void Substract(byteint SA,byteint SB,byteint SC); //SC=SA-SB void Multiply(byteint A,byteint B,byteint C); //C=A*B void SetMode(byteint A,byteint B,byteint C,byteint D);//C=A%B int PowerMode(byteint A,byteint C,byteint D,signed char flag[400]);//computing A^B mod C-->D void IntRandom(byteint RandomA,int num); //随机产生一个大数 void LoadInt(byteint A,mtype B); //将质数类型转换为大数类型 void TransBi(byteint B,signed char flag[400]); //将大数B转换为二进制形式 void Mdata(); //产生用于生成质数中进行比较的数 int Prime(byteint Prm); //产生一个长度为MLENGTH的质数 int ComputingPK(byteint Rvalue,byteint SK,byteint PK); //计算公钥PK void ComputingR(byteint p,byteint q,byteint R); //计算模值R void ComputingRvalue(byteint p,byteint q,byteint Rvalue); //计算$(r) void IntCpy(byteint A1,byteint B1); //将大数B1的值拷贝到大数A1中 void SetZero(byteint A); //将大数A清零 CString PrtInt(byteint A); //将一个大数类型转换为一个CString类型 int Getinput(byteint result,CString input); //将字符串转换为对应的大数形式 int Getinput1(byteint result,unsigned long input); //将长整形数转换为对应的大数形式 void RsaDo(byteint source,byteint R,byteint key,byteint desti); //实现加解密 unsigned long Os2ip(unsigned char* pstr); CString Ip2os(CString str); public: void GenKeys(CString& pk,CString& sk,CString& R); //提供给服务器使用的秘钥产生函数 int RsaEncrypt(CString& source,const char* key,const char* R,CStringArray& result);//加密 CString RsaDecrypt(CStringArray& source,const char* sk,const char* R);//解密 void GenKeysTable(); //生成秘钥对文件 void LoadKeysFromFile(CString& r,CString& sk,CString& pk); //成员变量 private: byteint ONEVALUE; byteint ZEROVALUE; byteint TWOVALUE; byteint EIGHTVALUE; //O,1,2,8 constant mtype Model[TESTNUM]; //TESTNUM big number to be compared mtype mZEROVALUE,tempModel; //0 constant signed char flag[400]; // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CRsaA) //}}AFX_VIRTUAL // Implementation //protected: virtual ~CRsaA(); // Generated message map functions //{{AFX_MSG(CRsaA) // afx_msg LONG OnComputing(WPARAM wParam, LPARAM lParam); // NOTE - the ClassWizard will add and remove member functions here. //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations im
wince上各种类型转换特别是字符串是很头疼的,这个类是项目用的, 每个都测试好用,使用静态方法,直接引用后,写【::cv::就可以用】 typedef int u32; //转换类,所有的转换函数在这里静态 2是to的意思 //cs:cstring //s:string //i:int class cv { public: static char * s2charx(string s); //static char * cs2charx_unicode(CString s); static char * cs2charx_unicode(CString s); static CString charx2cs(char *s); cv(); virtual ~cv(); static int cstring_to_int(CString t); static CString s2cs(string text); static CString i2cs(int i); static string cs2s(CString s); static void Utf8ToUnicode(wchar_t* pstrOut, u32 dwOutLen, const char* pstrIn, u32 dwInLen); static void Gb2312ToUnicode(wchar_t* pstrOut, u32 dwOutLen, const char* pstrIn, u32 dwInLen); static CString string_to_cstring(string text); static int string_to_int(string str); static string cstring_to_string(CString text); static void Gb2312ToUtf8(char* pstrOut, u32 dwOutLen, const char* pstrIn, u32 dwInLen); static BOOL IsNumeric(string text); static void UnicodeToGb2312(char* pstrOut, u32 dwOutLen, const wchar_t* pstrIn, u32 dwInLen); static void Utf8ToGb2312(char* pstrOut, u32 dwOutLen, const char* pstrIn, u32 dwInLen); static int cs2i(CString s); static string int_to_string(int n); static CString ChineseCapitalMoney(double Num); //static wstring s2ws( string s ); static std::wstring s2ws(const string& s); static std::string WChar2Ansi(LPCWSTR pwszSrc); static string ws2s(wstring& inputws); static const char * s2constcharx(string s); static std::wstring Ansi2WChar(LPCSTR pszSrc, int nLen); static char * cs2charx_ansi(CString s); //static string ws2s(wstring ws); };

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧