473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

type cast converting chars to CSring

I have a older C++ project from a pre .net Visual studio. I just want it to
run "the old way" in the new environment, not yet wanting to do any dotnet
stuff. Several conversions that worked before are errors now
The code
CString strAsciiLocation = (GetColumn() + 'a' - 1);
strAsciiLocation += (GetRow() + '0');
generates the error

c:\Documents and Settings\Charles\My Documents\Visual Studio Projects\Chess
Secratary\LocationOnBoard.cpp(207): error C2593: 'operator +=' is ambiguous
For the second line GetColumn and GetRow both return integers for example if
both returned 1 I wanted the string a1 for strAsciiLocation.

And
return CString('a' + FromLocation.GetColumn() -1)
+ CString('1' + FromLocation.GetRow() -1)
+ CString('a' + ToLocation.GetColumn() -1)
+ CString('1' + ToLocation.GetRow() -1);
generates four errors of the type
c:\Documents and Settings\Charles\My Documents\Visual Studio Projects\Chess
Secratary\Board.cpp(440): error C2440: 'type cast' : cannot convert from
'int' to 'ATL::CStringT<BaseType,StringTraits>'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
Although the first line of the first example doesn't generate an error.
Any suggestions on how to make these kinds of conversions in the new
environment?
Feb 16 '06 #1
2 1359

Silly me just put char() around everything and the world is beautiful again.
For example
strAsciiLocation += char(GetRow() + '0');
Feb 16 '06 #2
chasgl wrote:
I have a older C++ project from a pre .net Visual studio. I just want it to
run "the old way" in the new environment, not yet wanting to do any dotnet
stuff. Several conversions that worked before are errors now
The code
CString strAsciiLocation = (GetColumn() + 'a' - 1);
strAsciiLocation += (GetRow() + '0');
generates the error

c:\Documents and Settings\Charles\My Documents\Visual Studio Projects\Chess
Secratary\LocationOnBoard.cpp(207): error C2593: 'operator +=' is ambiguous
For the second line GetColumn and GetRow both return integers for example if
both returned 1 I wanted the string a1 for strAsciiLocation.

And
return CString('a' + FromLocation.GetColumn() -1)
+ CString('1' + FromLocation.GetRow() -1)
+ CString('a' + ToLocation.GetColumn() -1)
+ CString('1' + ToLocation.GetRow() -1);
generates four errors of the type
c:\Documents and Settings\Charles\My Documents\Visual Studio Projects\Chess
Secratary\Board.cpp(440): error C2440: 'type cast' : cannot convert from
'int' to 'ATL::CStringT<BaseType,StringTraits>'
with
[
BaseType=char,
StringTraits=StrTraitMFC_DLL<char>
]
Although the first line of the first example doesn't generate an error.
Any suggestions on how to make these kinds of conversions in the new
environment?


chasgl:

I think you need to cast all these expresssions to char.

But I'm not sure all this concatenation is the most efficient way to
generate these strings. In fact, since the length of these strings is
known up front, I wouldn't use CString at all.

David Wilkinson
Feb 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: yogi | last post by:
Hi guys, I'm trying to write a program that will read in a series of files and create a 3D array from the files read in for converting 2D images to 3D objects. The values read in will be...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
3
by: mra | last post by:
I want to cast an object that I have created from a typename to the corresponding type. Can anycone tell me how to do this? Example: //Here, Create the object of type "MyClass" object...
23
by: René Nordby | last post by:
Hi there, Is there anyone that knows how to do the following? I have a class A and a class B, that 100% inherits from class A (this means that I don't have other code in class B, than...
2
by: Peter Larsen | last post by:
Hi, How do i type cast a type to an array of type, e.g. IntPtr to IntPtr ?? /Peter
20
by: pinkfloydhomer | last post by:
Is it well-defined and portable to do something like: typedef struct { int type; char c; } S1; typedef struct {
16
by: Martin Jørgensen | last post by:
Hi, Short question: Any particular reason for why I'm getting a warning here: (cast from function call of type int to non-matching type double) xdouble = (double)rand()/(double)RAND_MAX;
13
by: archuleta37 | last post by:
I'm trying to cast a String from a web forms textbox into an Int16 (see code below), but it's not quite working. When I post the textbox with numbers (no alpha chars) I get the following error in...
5
by: vtjumper | last post by:
I'm building a C# interface to an existing messaging system. The messaging system allows values of several types to be sent/recieved over the interface. What I want to do is use a generic...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.