[RESOLVED]: Compile Error during project conversion from VC++6.0 to VC++ 2005 [modified]
-
Hi all, I have the below code: str.Replace("\r\n", CString((unsigned char)0xB6)); Here i have a CString object 'str' with some string value. It seems '0xB6' stands for line separator or something.. Im not sure.. Well this is the existing code. But when i tried to convert the project to VC++ 2005 i am getting the compile error as: error C2440: '' : cannot convert from 'int' to 'CString'; No constructor could take the source type, or constructor overload resolution was ambiguous. Kindly help to resolve this error. Thanks
Priya Sundar
modified on Monday, March 10, 2008 1:03 AM
-
Hi all, I have the below code: str.Replace("\r\n", CString((unsigned char)0xB6)); Here i have a CString object 'str' with some string value. It seems '0xB6' stands for line separator or something.. Im not sure.. Well this is the existing code. But when i tried to convert the project to VC++ 2005 i am getting the compile error as: error C2440: '' : cannot convert from 'int' to 'CString'; No constructor could take the source type, or constructor overload resolution was ambiguous. Kindly help to resolve this error. Thanks
Priya Sundar
modified on Monday, March 10, 2008 1:03 AM
just try not to enforce into
unsigned char
:str.Replace("\r\n", CString((char)0xB6));
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
just try not to enforce into
unsigned char
:str.Replace("\r\n", CString((char)0xB6));
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
Yes it did resolve my error. But now i am getting a warning. "warning C4310: cast truncates constant value" I need to assign a value between 0 - 127 to resolve the warning. But since the val for 0xb6 is 182, will i not be able to eliminate this warning? Any suggestions?
Priya Sundar
-
Hi all, I have the below code: str.Replace("\r\n", CString((unsigned char)0xB6)); Here i have a CString object 'str' with some string value. It seems '0xB6' stands for line separator or something.. Im not sure.. Well this is the existing code. But when i tried to convert the project to VC++ 2005 i am getting the compile error as: error C2440: '' : cannot convert from 'int' to 'CString'; No constructor could take the source type, or constructor overload resolution was ambiguous. Kindly help to resolve this error. Thanks
Priya Sundar
modified on Monday, March 10, 2008 1:03 AM
Try some thing like this,
CString tempStr; tempStr.Format("%d",0xB6); str.Replace("\\r\\n", tempStr);
-
Yes it did resolve my error. But now i am getting a warning. "warning C4310: cast truncates constant value" I need to assign a value between 0 - 127 to resolve the warning. But since the val for 0xb6 is 182, will i not be able to eliminate this warning? Any suggestions?
Priya Sundar
Priya_Sundar wrote:
Yes it did resolve my error. But now i am getting a warning. "warning C4310: cast truncates constant value" I need to assign a value between 0 - 127 to resolve the warning. But since the val for 0xb6 is 182, will i not be able to eliminate this warning? Any suggestions? Priya Sundar
The actual range of acceptable values should be -128 to 127, and I think 0xB6 maps to -74. However, I think unsigned char is the right type for what you are doing, and CString requiring a signed character poses a problem. You may be able to use a string
"\xB6"
instead of a character to initialize the CString. Nathan -
Hi all, I have the below code: str.Replace("\r\n", CString((unsigned char)0xB6)); Here i have a CString object 'str' with some string value. It seems '0xB6' stands for line separator or something.. Im not sure.. Well this is the existing code. But when i tried to convert the project to VC++ 2005 i am getting the compile error as: error C2440: '' : cannot convert from 'int' to 'CString'; No constructor could take the source type, or constructor overload resolution was ambiguous. Kindly help to resolve this error. Thanks
Priya Sundar
modified on Monday, March 10, 2008 1:03 AM
There are two overloads of CString::Replace: one takes two LPCTSTR parameters while the other takes two TCHAR parameters. When converting to Visual C++ 2005 you normally run into two issues: 1. The default character type is now Unicode; 2. The new compiler is more conformant to the C++ standard Here you have an additional complication that CString has changed significantly (it's now a template, for example). The MFC 6.0 version would have called the CString constructor that takes a TCHAR ch and an integer nRepeat, which was defaulted to 1. This version of the constructor generated a string of nRepeat copies of ch. This still exists in MFC 8.0 but has been marked
explicit
, which means that the types must match exactly. However, calling a CString constructor is unnecessary - you should instead use a string literal.str.Replace( "\r\n", "\xb6" );
Because of the change to Unicode, you may find you need to put
_T()
around both string literals.DoEvents: Generating unexpected recursion since 1991
-
There are two overloads of CString::Replace: one takes two LPCTSTR parameters while the other takes two TCHAR parameters. When converting to Visual C++ 2005 you normally run into two issues: 1. The default character type is now Unicode; 2. The new compiler is more conformant to the C++ standard Here you have an additional complication that CString has changed significantly (it's now a template, for example). The MFC 6.0 version would have called the CString constructor that takes a TCHAR ch and an integer nRepeat, which was defaulted to 1. This version of the constructor generated a string of nRepeat copies of ch. This still exists in MFC 8.0 but has been marked
explicit
, which means that the types must match exactly. However, calling a CString constructor is unnecessary - you should instead use a string literal.str.Replace( "\r\n", "\xb6" );
Because of the change to Unicode, you may find you need to put
_T()
around both string literals.DoEvents: Generating unexpected recursion since 1991
Thankyou very much. My errors are resolved.
Priya Sundar